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 RDB
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 RDB

Introduction to Redis RDB

Redis rdb persistence performs point in time snapshots of our dataset at specific time intervals. Basically, rdb in redis is used to take the backup of our database in a specific time interval that we have defined. It is a very compact and single-file point-in-time representation, which is used for redis data. Redis rdb file is perfect for data backups, we can easily take backups.

Redis RDB

Key Takeaways

  • Redis rdb is very good for disaster recovery by using a single compact file which is transferred by data centers onto the S3 bucket.
  • While executing the save command, it will return the string OK, indicating that no errors were defined in the specified command.

What is Redis RDB?

For the specified instance if we want to archive the rdb file every hour then it will allow us to easily restore different types of versions of the data set in case a disaster will happen. It will maximize the performance of the redis parent process which we need to persist at the time of forking the child which we do at rest.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The parent process of redis rdb will not perform disc I/O. When compared to the AOF, Redis rdb will allow for faster restarts by using larger datasets. As we all know, backup is essential for any database. It will allow us to perform restorations in the case of errors or failures. We provide protection to the redis database by enabling rdb snapshots.

How to Use Redis RDB File?

The below steps show how we can use the redis rdb file as follows. We need to install the redis on our system.

1. First we are installing the redis as follows. We are using the apt command to install the same as follows.

Command:

# apt install redis-server

Output:

Installing Redis RDB

2. While installing the redis server in the second step we are starting the same by using the below command as follows. Basically, it will not start automatically in the ubuntu system.

Command:

# redis-server

Output:

Redis RDB Server Command

3. While starting the redis server now we are login into the server by using the below command as follows.

Command:

# redis-cli

Output:

Redis RDB Login

4. While logging, now we are executing the set command then we are using the save command to create the backup by using redis rdb as follows.

Command:

SET key1 val1
SAVE

Output:

Executing the set command

5. After executing the save command we can see that the dump.rdb file is created in the specified location as follows.

Redis RDB Save Command

Redis RDB Tools

Redis rdb tools is an open source memory profiling tool for redis that parses redis dump files and generates memory profiling in various formats after parsing the file. This tool provides us with visibility into memory usage and helps us in resolving a variety of customer issues. This tool is very useful for redis point-in-time backup. This tool’s first version was created in 2018.

The rdb tools version online is a SaaS version but we need the self-hosted version of rdb tools. We can start the rdb tools by using the docker container.

Below figure shows how we can install the rdb tools in our system as follows:

Command:

# pip install rdbtools

Output:

Install Redis RDB Tools

Rdb tool contains the multiple customers used to save costs. Redis dump file parses redis dump files and exports the data to JSON; it also analyses memory while parsing the dump file.

Rdb tools also provide the below utility. Basically, rdb tools are written into python.

Below is the utility of rdb tools as follows:

  • Generating memory reports of our data across the keys and databases.
  • Convert the dump files into JSON.
  • Compare the two dump files by using standard tools.

In the below example we are using rdb tools for converting the rdb file into the JSON as follows:

Command:

# rdb --command json dump.rdb

Output:

Converting the rdb file

We can also parse the output of the rdb file by using the following command. In the below example, we are displaying the key1 output as follows.

Command:

# rdb --command justkeyvals --key "key1.*" dump.rdb

Output:

displaying the key1

Steps to Restore Data Redis RDB

1. In the first step we are checking whether the AOF is enabled or disabled in our system, Suppose it is enabled then we need to disable it. In the below example, we can see that it is enabled as it’s showing yes in output.

Command:

# redis-cli CONFIG GET appendonly

Output:

Redis RDB 11

2. In above example we can see that AOF is enabled so in this step we need to disable the same by using below command as follows.

Command:

# redis-cli CONFIG SET appendonly no
# redis-cli CONFIG GET appendonly

Output:

Redis RDB 12

3. After disabling the AOF, now in this step we are stopping the redis server by using below command as follows.

Code:

# redis-cli SHUTDOWN

Output:

we are stopping

4. After shutting down the redis server, now in this step we are removing the aof and rdb file as follows.

Command:

# rm *.aof *.rdb

Output:

removing the aof

5. After removing the aof and rdb file, now in this step we are copying the rdb file in redis directory as follows.

Command:

# cp dump.rdb /var/lib/redis/

Output:

Redis RDB 15

6. After copying the file now in this step, we are starting the redis server by using restored data as follows.

Command:

# redis-server

Output:

restored data

Features

Below are the features of redis rdb as follows. Redis rdb is useful in point in time recovery for storing the data.

  • Compactness – The resulting snapshot file is used to map the value of keys. Redis supports the compression of LZF.
  • Performance – Because we generate snapshots in the background, rdb compression has no effect on redis database performance.
  • Faster restarts – While restarting the redis server we need to load the entire dataset, same time rdb is useful.
  • Durability – Redis rdb is durable, it is very reliable into the system software which as we have defined.
  • Transparency – The file of rdb is trivial as compared to the rdb snapshot.
  • File size – The file size of redis rdb is smaller as compared to the AOF file so we can easily restore the same.
  • Persistence – The rdb backup file is more persistence as compared to the AOF file into the redis.

FAQs

Given below are the FAQs mentioned:

Q1. What is the use of redis rdb?

Answer: It is used to create the snapshot backup. We are creating the specified backup as per specified time frame.

Q2. What is the use of save command in redis rdb?

Answer: Save command into the redis rdb is used for creating snapshot backup. This command will lock the another user until it finishes this operation.

Q3. What is the use of bgsave command in redis rdb?

Answer: Bgsave command into the redis rdb is used for creating snapshot backup. This command will not lock the client; instead, it will run in the background.

Conclusion

The parent process of redis rdb will not perform disc I/O. Redis rdb persistence takes point-in-time snapshots of our dataset at predefined intervals. Basically, rdb in redis was used to take a backup of our database at a predefined time interval.

Recommended Articles

This is a guide to Redis RDB. Here we discuss the introduction, how to use redis RDB file, tools, features and FAQs. 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