Trending September 2023 # How To Use Cli To Flush Redis Cache? # Suggested October 2023 # Top 14 Popular |

Trending September 2023 # How To Use Cli To Flush Redis Cache? # Suggested October 2023 # Top 14 Popular

You are reading the article How To Use Cli To Flush Redis Cache? updated in September 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How To Use Cli To Flush Redis Cache?

Introduction to Redis FLUSHDB

In simple, the Redis FLUSHDB option is implied to delete every key in the selected database. The FLUSHDB command never fails in any case and it is available since version 1.0. The time complexity is defined as O (N) where N signifies the count of keys in the chosen database. It applies to all categories like slow, dangerous, writes, and keyspace.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Key Takeaways

Redis 4.0 and after that version can able to delete all keys in the background as a single thread without server blocking.

Async option is used for FLUSHDB and FLUSHALL in the entire dataset.

Due to security reasons, the user wants to hide the authentication password from others in the Linux and not expose it.

The Redis FLUSHDB command removes every key in the chosen database and once executed, this command never fails.

What is Redis FLUSHDB?

Redis FLUSHDB is used to remove all the present keys from the selected database. By default, to flush the keys synchronously from the database, use the FLUSHDB command. From Redis 6.2, fix the lazy free config settings to yes, to change the mode from synchronous to asynchronous. It can be used with modifiers to work according to the flushing mode given.

ASYNC is used to flush the DB in an asynchronous way.

SYNC is used to flush the DB in a synchronous way.

Keys generated at asynchronous flush will stay unaffected, and when the asynchronous FLUSHDB command is invoked, it deletes only the keys that are present. In this blog, the user can learn to remove all the keys present in the database and can clear the cache with a simple method.

Redis FLUSHDB Empty

Redis is an open-source, free, key-value data store that saves the data in the memory of the system instead of the disk. This is the unique feature that enables Redis to be cognitive and extremely compute compared to other relational database. It is an important feature that has effective performance in a minimum latency environment.

Redis-CLI FLUSHDB command allows the user to remove keys from the pointed database.

If the Redis is executed on the remote machine, the user can give the address of the host machine using –h as below:

If the user wants to target the specific database index, he can use –n followed by an index of the database.


Redis cli –n [index of the db] FLUSHDB

If the user gives 11, it clears all the keys at index 11.

Redis cli –n 11 FLUSHDB

Since Redis 4.0, enables the user to execute flush operations on the segregated thread, it also restricts the flush operation from restricting the server till it gets completed.

To execute the asynchronous flush operation, follow the below command:

Redis CLI FLUSHDB async Redis FLUSHDB Server Command

To delete everything from the Redis, two major commands are FLUSHALL and FLUSHDB. It will be easy if those commands are executed in Redis CLI.

The FLUSHDB command executes the delete operation in keys present in the database. The FLUSHALL commands remove all the keys present in the database.

Redis FLUSHDB Key and Scan

The iterator based on the scan signifies every call on commands and the server executes the updated cursor values which the user applies to the argument in the successor call.


SCAN [ pattern match ] [count]

The Redis scan command is applied to increase the iteration over the element collection. Every iteration starts when the pointer is fixed to 0 and stops when the pointer or cursor gives the output from the server as 0. The option is available from the version Redis 2.8.0

The new cursor has the first value, which should be used in the next call and the second value comprises an array of the element. In the second call, if the value is returned to 0, and waits till the scan returns 0, which is the full iteration.

Redis FLUSHDB Syntax to Cache

The easy method to clear the cache is by using the Redis CLI utility. In the Redis command line interface, the user can delete all the keys present in a database available in the cluster of Redis.


The database number enables the user to look at the target database that needs to be erased. Option – is given for clear operation.

It should be noted that the hostname of the server is and the default port is 6379 give a password and socket when connecting to the server by using the syntax below.

Redis cli -h {hostname of the machine_IP} -p {port number} -s {socket} -a {password} FLUSHDB Redis cli -h {hostname of the machine_IP} -p {port number} -s {socket} -a {password} FLUSHALL FAQ

Given below are the FAQs mentioned:

Q1. How to Authenticate the Redis database?

The user can simply REDIS CLI _ AUTH as an environment variable to surpass the password in a secure method.


REDIS CLI_AUTH='mypassword' Redis CLI -p 6379 FLUSHDB Q2. How to Clear the Redis cache?


The default hostname is and the number of Redis ports is 6379.


$ Redis cli -h {hostnmachine IP} -p {portnumber} Q3. How to Delete keys from a particular DB?



Redis cli –n [index of the db] FLUSHDB Conclusion

Hence, these are the few basic operations using the FLUSHDB command in Redis. It is a user-friendly and reliable method to work effectively on the Redis database as it deals with higher dimensional data.

Recommended Articles

This is a guide to Redis FLUSHDB. Here we discuss the introduction, server command, syntax few basic operations using the FLUSHDB command. You may also have a look at the following articles to learn more –

You're reading How To Use Cli To Flush Redis Cache?

Update the detailed information about How To Use Cli To Flush Redis Cache? on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!