1. Export Redis
#!/bin/bash
redis_host=localhost
redis_port=6379
redis_db=1
keyname=redis:hash:*
KEYFILE= Key.txt
echo "KEYS $KEYNAME" | redis-cli-h $REDIS _host-p $REDIS _port-n $REDIS _db > $KEYFILE
outfile=valuelis T.txt
tempfile= $OUTFILE. tmp
echo > $TEMPFILE for
key in ' Cat $KEYFILE '
do
echo $key
#echo "Hgetall $key" | Redis-cli-h $REDIS _host-p $REDIS _port-n $REDIS _db >> $TEMPFILE
echo "Get $key" | redis-cli-h $REDIS _h Ost-p $REDIS _port-n $REDIS _db >> $TEMPFILE done
2, sorting out the results of the export
Cat $TEMPFILE |xargs-n 2|awk-f "" v keyname= $KEYNAME ' {print "Hset" KeyName "" $, "" $ ""} "> $OUTFILE
The Xargs-n 2 is a line of 2 lines, and a newline character is replaced with a space
And then using awk to separate the spaces, $ is Keynam $ is the value of the key
Convert again to Hset format, where you use the KeyName variable, which is defined with-V.
Finally converted to Hset keyname KEY "VALUE" format.
3, the results of the import transformation
Cat $OUTFILE | Redis-cli-h localhost-p 6379
Two, directly with the Redis dump and restore export and import
Redis-cli--raw Dump Test | head-c-1 | Redis-cli-x Restore Test1 0