Read more

Delete specific Redis-DBs

Stefan Xenopol
January 17, 2023Software engineer at makandra GmbH

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.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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
January 17, 2023Software engineer at makandra GmbH
Posted by Stefan Xenopol to makandra Operations (2023-01-17 16:22)