This post will guide you how to delete all keys and flush all Redis caches in your redis server. How do I delete everything in Redis.
Delete All Keys
You can flush cache or database and delete all keys from all databases or a specific database in your redis server. and you can use the FLUSHALL and FLUSHDB commands to achieve the result.
Delete All keys from All Databases
If you want to delete all keys from all Redis databases, you can use the FLUSHALL command. type:
devops@devops-osetc:~$ redis-cli 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> flushall OK
Or you can issue the following command to achieve the same result:
$redis-cli flushall
This command will destroy everything of all the existing database.
Delete All Keys from a Specific Database
If your Redis server is running multiple databases, you can use the select command to connect to that specific database, for example, you want to connect to one database its index number is 1, you can type the following command:
127.0.0.1:6379> select 1
Outputs:
devops@devops-osetc:~$ redis-cli 127.0.0.1:6379> select 1 OK
Then you can use the FLUSDB command to delete all keys from this selected Redis database, issue the following FLUSHDB command:
devops@devops-osetc:~$ redis-cli 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> flushdb OK 127.0.0.1:6379[1]>
Or you can use another command to achieve the same result, type:
$ redis-cli -n 1 flushdb
See Also: