How to flush Redis cache and delete everything using the CLI

I setup Redis cache for my web app. I want a blank database and get rid of all keys. How can I delete everything in Redis cache? How do I flush my Redis cache using the Linux/Unix command line option? What is the command to delete all keys from my redis cluster?

You can flush cache/database and delete all keys using any one of the following redis-cli command:

  1. FLUSHDB command – Delete all the keys of the currently selected DB.
  2. FLUSHALL command – Delete all the keys of all the existing databases, not just the currently selected one.

How to Delete All Data in Redis
Please note that Redis version 4.0.0 and above is now able to delete keys in the background in a different thread without blocking the server. An ASYNC option was added to FLUSHALL and FLUSHDB in order to let the entire dataset or a single database to be freed asynchronously.

Warning: Once removed data/keys/values can not be recovered. Be careful when typing the following commands.

Syntax to flush Redis cache

The syntax is as follows for flushing Redis cache from the shell prompt:
redis-cli FLUSHDB
redis-cli -n DB_NUMBER FLUSHDB
redis-cli FLUSHALL

The default server hostname is set to and port to 6379. We can override it as follows:
$ redis-cli -h {host-name} -p {port-name} command
$ redis-cli -h -p 6000 FLUSHDB
$ redis-cli -h FLUSHALL

You can give password to use when connecting to the server by passing the -a option to the redis-cli:
$ redis-cli -a '{password-here}' COMMAND
$ redis-cli -a 'SuperSecretPassword' -h -p 6379 -n 2 FLUSHDB

Examples – Delete All Keys using redis-cli

Type the following command to delete all the keys of the DB # 4:
$ redis-cli -n 4 FLUSHDB
Sample outputs:


To remove all the keys of all the existing database, run:
$ redis-cli FLUSHALL
Sample outputs:


Automation of deleting Redis cache using Ansible devops tool

Say you have 10 different Redis server running and you want to remove all the keys of all existing DBs. Create a host file as follows:
$ cat hosts
Sample outputs:


Now all you have to do is run the following command (assuming that SSH keys are set between your workstation and all other VMs/bare metal servers)
$ ansible -i hosts redis -m command -a '/usr/bin/redis-cli FLUSHALL'
Sample outputs:

vm1-eu | SUCCESS | rc=0 >>

vm2-us | SUCCESS | rc=0 >>

vm3-bom | SUCCESS | rc=0 >>

vm4-del | SUCCESS | rc=0 >>

vm5-nyc | SUCCESS | rc=0 >>

vm6-eu-2 | SUCCESS | rc=0 >>

vm7-linod-fr-1 | SUCCESS | rc=0 >>

vm8-do-blr-1 | SUCCESS | rc=0 >>

vm9-do-blr-2 | SUCCESS | rc=0 >>

m10-linod-tx-1 | SUCCESS | rc=0 >>

A note about redis cluster

Are you using a cluster? You need to run the FLUSHDB or FLUSHALL command on every master node. For example, run the following command on three master node using bash for loop

# three master node ip address
for s in
  echo "Flushing DB from $s node ..."
  redis-cli -h $s FLUSHDB

Flushing redis cache / node from console when using AWS Elasticache cluster

No need to reboot the node. You can run above commands from the EC2 cloud server/host or using API:
# FLUSH everything #
$ redis-cli -h AWS-Elasticache-Host -p AWS-Port_Number FLUSHALL
# FLUSH by DB_NUMBER aka specific DB #
$ redis-cli -h AWS-Elasticache-Host -p AWS-Port_Number -n DB_NUMBER FLUSHDB


You learned how to flush redis cache and delete all keys using the command line option. For more info read the official redis docs here and here.

This entry is 2 of 2 in the Redis Server Tutorial series. Keep reading the rest of the series:
  1. How to install Redis server on Ubuntu Linux 16.04
  2. How to flush Redis cache and delete everything using the CLI

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Singpho Jul 18, 2020 @ 13:28

    Awesome post finally problem solved!
    actually i was having error of domain caching by redis on cyberpanel, googled for 24 hrs and finally found the real solution here !
    THANKS cyberciti!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum