Claus-Theodor Riegg
1 year
Moritz Kraus
1 year
Claus-Theodor Riegg
1 year
Stefan Xenopol
1 year
Claus-Theodor Riegg
8 years
Andreas Vöst
2 years

Delete specific Redis-DBs

Posted . Visible to the public.

To delete a specific redis-DB you need to use the FLUSHDB-command in combination with the SELECT-command. For more information have a look at the documentation for FLUSHDB Show archive.org snapshot and SELECT Show archive.org snapshot .

Attention

By default when connecting to a redis-instance you always connect with db0.

When connecting to the db you can list your keyspaces/databases with:

# Show info about all databases
127.0.0.1:6379> INFO keyspace
# Keyspace
db0:keys=2674,expires=2663,avg_ttl=99821491105
db1:keys=478,expires=466,avg_ttl=33842000297
db2:keys=12,expires=6,avg_ttl=23445951871

In this example you can see that we have 3 DBs.

If you are unsure which DB you want to remove have a look at the keys in the databases by selecting the database and then listing all keys.

# Select db1
127.0.0.1:6379> SELECT 1
OK
127.0.0.1:6379[1]>

# List all keys
127.0.0.1:6379[1]> KEYS *
[possibly long output or "empty list or set"]

In order to delete the keys you need to select the DB first and then remove all keys using FLUSHDB

Note

If you are using a redis cluster this will delete the database across all nodes in your cluster.

# Select db1
127.0.0.1:6379> SELECT 1

# If possible, check if keys can be really deleted
127.0.0.1:6379[1]> KEYS *

# Remove all keys
127.0.0.1:6379[1]> FLUSHDB

# Double check if all keys are gone
127.0.0.1:6379[1]> KEYS *
(empty list or set)
Stefan Xenopol
Last edit
Marius Schuller
License
Source code in this card is licensed under the MIT License.