centos下redis的导出和导入(限set命令)

#!/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

上一篇:ES6 一些笔记


下一篇:用Chrome开发者工具做JavaScript性能分析