Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Several methods of importing and exporting redis data

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor to share with you is several redis data import and export methods, many people do not understand, today, in order to let you know more about redis data import and export methods, so to sum up the following content, let's look down. I'm sure you'll get something.

Redis, that is, remote dictionary service, is an open source log database written in ANSI C language, which supports network, memory-based and persistent Key-Value database, and provides API in multiple languages.

Several ways to import and export redis data:

I. redis-dump mode

# redis-dump install yum install ruby rubygems ruby-devel-ygem sources-- add http://gems.ruby-china.com/-- remove https://rubygems.org/[root@docker ~] # gem sources-lingual installation * CURRENT SOURCES * http://gems.ruby-china.com/ # confirm that this is the only one [root@docker ~] # curl-L get.rvm.io | bash-s stable

Gpg2-- keyserver hkp://pool.sks-keyservers.net-- recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB execute again: [root@docker ~] # source / etc/profile.d/rvm.sh [root@docker ~] # rvm-vrvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

List known ruby packages and install:

[root@docker ~] # rvm list known [root@docker ~] # rvm install 2.4

Install redis-dump

Gem install redis-dump-V

Import and export

Redis-dump Export [root@ ~] # redis-dump-u: password@172.20.0.1:6379 > 172.20.0.1.jsonredis-load Import [root@ ~] # cat 172.20.0.1.json | redis-load-u: password@172.20.0.2:6379

II. Import by aof

III. Rdb file migration mode

1. Original redis server

Log in to the redis server and connect to redis through the client of redis, with the following command:

[root@ ~] # redis-cli127.0.0.1:6379 >

Note: if redis-cli is not installed as a service, you can go to the src directory of redis to connect to the client.

After the connection is successful, we can find the file storage directory of redis with the following command

127.0.0.1 var/lib/redis 6379 > CONFIG GET dir "dir" / var/lib/redis "127.0.0.1

Comments: under / var/lib/redis

Let's take a look at the trigger conditions for redis data backup and look at the redis configuration file / ect/redis.conf. We can see that the trigger conditions for redis data backup are:

At least one key has been changed in save 9001 # 900s for backup

At least 300 key have been changed in save 30010 # 300s for backup

At least 10000 key have been changed in save 60 10000 # 60 seconds for backup

We can directly back up the data at this time by save. The command is as follows:

[root@ ~] # redis-cli127.0.0.1:6379 > save # data backup 127.0.0.1 save 6379 > # exit

At this time, we can see the dump.rdb files that have just been backed up in the redis file storage directory / var/lib/redis directory.

2. Target server

Log in to the target redis server and stop the redis service first:

Service redis stop # stop the redis service

Then go to the redis file storage directory / var/lib/redis, and replace the dump.rdb file you just backed up with the dump.rdb file in that directory.

(it is recommended to back up the dump.rdb files in the current directory first) and restart the redis service

Service redis start # start the redis service

At this point, the redis data migration is complete.

These are the details of several redis data import and export methods, after reading it, do you have anything to gain? If you want to know more about it, welcome to the industry information!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report