Redis is the remote dictionary service. It is an open source log-type Key-Value database written in ANSI C language, supports the network, can be memory-based and persistent, and provides APIs in multiple languages.
Several methods of importing and exporting redis data:
1. redis-dump method
#redis-dump安装 yum install ruby rubygems ruby-devel -y gem sources --add http://gems.ruby-china.com/ --remove https://rubygems.org/ [root@docker ~]# gem sources -l *** CURRENT SOURCES *** http://gems.ruby-china.com/ #确定只剩这一个 [root@docker ~]# curl -L get.rvm.io | bash -s stable
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 再执行一遍: [root@docker ~]# source /etc/profile.d/rvm.sh [root@docker ~]# rvm -v rvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
List known ruby packages and install them:
[root@docker ~]# rvm list known [root@docker ~]# rvm install 2.4
Install redis-dump
gem install redis-dump -V
Import and export
redis-dump导出 [root@ ~]# redis-dump -u :password@172.20.0.1:6379 > 172.20.0.1.json redis-load导入 [root@ ~]# cat 172.20.0.1.json | redis-load -u :password@172.20.0.2:6379
2. AOF import method
## 3. RDB file migration method
1. Original redis serverLog in to the redis server, and then connect to redis through the redis client. The command is as follows:[root@ ~]# redis-cli 127.0.0.1:6379>Note: If redis-cli is not installed as a service, you can enter the src directory of redis to perform client operations. End connectionAfter the connection is successful, we can find the redis file storage directory through the following command
127.0.0.1:6379> CONFIG GET dir "dir" "/var/lib/redis" 127.0.0.1:6379>Note: Under /var/lib/redisLet’s check below Let’s take a look at the triggering conditions for redis data backup. Check the redis configuration file /ect/redis.conf. You can see that the triggering conditions for redis data backup are:
save 900 1 #At least 1 within 900 seconds The key is changed, make a backup save 300 10 #At least 300 keys have been changed within 300 seconds, make a backupsave 60 10000 #At least 10,000 keys have been changed within 60 seconds, BackupWe can directly back up the data at this time through save. The command is as follows:
[root@ ~]# redis-cli 127.0.0.1:6379> save #数据备份 127.0.0.1:6379> #退出At this time we can store the redis file in the directory / See the dump.rdb file just backed up in the var/lib/redis directory2. Target serverLog in to the target redis server, let’s stop the redis service first:
service redis stop #停止redis服务Then enter the redis file storage directory /var/lib/redis, and replace the dump.rdb file just backed up with the dump.rdb file in that directory (it is recommended to back up the dump.rdb file in the current directory first) , restart the redis service
service redis start #启动redis服务At this point, the redis data migration is completed. For more redis knowledge, please pay attention to the
redis tutorial column on the PHP Chinese website.
The above is the detailed content of redis data import and export. For more information, please follow other related articles on the PHP Chinese website!