redis USES redis dump to export import and restore data instances


Backup and restore of redis, with the help of a third tool, redis-dump

1. Install redis-dump

[root@localhost tank]# yum install ruby rubygems ruby-devel   // The installation rubygems  And related packages  
[root@localhost tank]# gem sources -a http://ruby.taobao.org/   // Source, join taobao, outside the source can not be accessed  
http://ruby.taobao.org/ added to sources 
[root@localhost tank]# gem install redis-dump -V   // The installation redis-dump 

2. redis-dump export data

[root@localhost tank]# telnet 127.0.0.1 6379 //telnet to redis 
Trying 127.0.0.1... 
Connected to 127.0.0.1. 
Escape character is '^]'. 
set test 11 // Set up the 1 A value  
+OK 
get test // The values  
$2 
11 
 
[root@localhost tank]# redis-dump -u 127.0.0.1:6379 >test.json // Export data  

3. Restore data by redis-load

[root@localhost tank]# telnet 127.0.0.1 6379 //telnet to redis 
Trying 127.0.0.1... 
Connected to 127.0.0.1. 
Escape character is '^]'. 
flushall // Please empty all data  
+OK 
keys * // View cleared  
*
 
[root@localhost tank]# < test.json redis-load // Import data  
 
[root@localhost tank]# telnet 127.0.0.1 6379 
Trying 127.0.0.1... 
Connected to 127.0.0.1. 
Escape character is '^]'. 
keys * // Imported successfully  
*
$4 
test