EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Redis Tutorial Redis FLUSHDB
Secondary Sidebar
Redis Tutorial
  • Redis
    • Redis Pubsub
    • Redis GUI
    • Redis Database
    • Redis Get All Keys
    • Redis TTL
    • Redis EXPIRE
    • Redis Version
    • Redis EXPIRE
    • Redis List
    • Redis CLI Commands
    • Redis HSET
    • Redis FLUSHDB
    • Redis Key
    • Redis Persistence
    • Redis FLUSHALL
    • Redis pipeline
    • Redis SADD
    • Redis ZADD
    • Redis ZSET
    • Redis Get
    • Redis Replication
    • Redis Delete All Keys
    • Redis Use Cases
    • Redis HMSET
    • Redis Transactions
    • Redis Monitor
    • Redis HGET
    • Redis SETEX
    • Redis Rails
    • RedisJSON
    • Redis Get Key
    • Redis Auth
    • Redis gem
    • Redis Key Count
    • RedisTimeSeries
    • Redis Timeout
    • Redis LPUSH
    • Redis Architecture
    • Redis API
    • Redis Message Queue
    • Redis RPUSH
    • Redis Protocol
    • Redis Data Types
    • Redis Namespace
    • Redis ZRANGE
    • Redis Master Slave
    • Redis Memory Usage
    • Redis WATCH
    • Redis URL
    • Redis Key Value
    • Redis INCR
    • Redis EXISTS
    • Redis INFO
    • Redis HMGET
    • Redis Operator
    • Redis NOAUTH Authentication Required
    • Redis LRANGE
    • Redis RDB
    • Redis TLS
    • Redis HDEL
    • Redis WebSocket
    • Redis HGETALL
    • Redis GETSET
    • Node-RED WebSocket

Redis FLUSHDB

Redis FLUSHDB

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.

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Few modifiers are:

  • 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:

Redis cli –h < IP of host machine > FLUSHDB

It is advised to use the FLUSHDB command without passing any argument as it removes every key in the pointed database. If it is not given, the default database will start from index 0.

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

Syntax:

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.

The command executes the operation in the backend thread with the async option. If it takes a long time to flush by using the async option, it gets blocked till gets completed. The user checks on the option that is present after Redis 4.0

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.

Syntax:

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.

Syntax:

Redis cli <number of the database> < option >

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 127.0.0.1 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?

Answer: 

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

Syntax:

REDIS CLI_AUTH='mypassword' Redis CLI 10.8.5.4 -p 6379 FLUSHDB

Q2. How to Clear the Redis cache?

Answer:

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

Command:

$ Redis cli -h {hostnmachine IP} -p {portnumber}

Q3. How to Delete keys from a particular DB?

Answer:

Code:

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 –

  1. Redis Get All Keys
  2. Redis GUI
  3. Redis Pubsub
  4. Redis Version
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more