#!/bin/bash
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=10

KEYNAME="*"
KEYFILE=redis_key.txt
echo "KEYS $KEYNAME" | redis-cli -h $REDIS_HOST -p $REDIS_PORT -n $REDIS_DB > $KEYFILE

OUTFILE=redis_valuelist.txt
TEMPFILE=$OUTFILE.tmp
for key in `cat $KEYFILE`
do
echo $key >> $TEMPFILE
echo "GET $key" | redis-cli -h $REDIS_HOST -p $REDIS_PORT -n $REDIS_DB >> $TEMPFILE
done

cat $TEMPFILE|xargs -n 2|awk -F" " -v KEYNAME=$KEYNAME '{print "HSET " $1, "\""$2"\""}' > $OUTFILE

导入到指定的库

cat $OUTFILE | redis-cli -h localhost -p 6379 -n 4

04-18 00:39