使用redis-cli dump数据的bash脚本
作者:
ehocchen | 来源:发表于
2020-01-16 11:28 被阅读0次
来源: http://chocksaway.com/code/redis/2016/05/10/bash-script-for-dumping-all-key-values-using-redis-cli.html
#!/bin/bash
# get all keys
# find the type for each key
# get value(s) for key
# list, string, hash, set
for each in $( redis-cli KEYS \* ); do
result=$(redis-cli type $each)
value=""
if [ $result == "list" ]
then
value=$(redis-cli lrange $each 0 -1)
elif [ $result == "string" ]
then
value=$(redis-cli get $each)
elif [ $result == "hash" ]
then
value=$(redis-cli hgetall $each)
elif [ $result == "set" ]
then
value=$(redis-cli smembers $each)
fi
printf "key %s\t\t type %s\t\t value %s.\n" $each $result $value
done
本文标题:使用redis-cli dump数据的bash脚本
本文链接:https://www.haomeiwen.com/subject/lprfzctx.html
网友评论