-
-
Save arc279/61f2e86e232ca84c1873953dbd927294 to your computer and use it in GitHub Desktop.
redis hash dump by hscan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function dump_redis_hash_to_json() { | |
# redis の hash をjsonに出力 | |
key=$1 | |
num=$2 | |
output=$3 | |
cr=0 | |
while true; do | |
cr=$(redis-cli -n 12 HSCAN $key $cr MATCH '*' COUNT $num | { | |
read a | |
while read x; read y; do | |
jo tuuid=$x attrs=$y >&${output} | |
done | |
echo $a | |
}) | |
echo $cr >&2 | |
if [ $cr == "0" ]; then | |
break | |
fi | |
done | |
} | |
set -ue | |
exec {fd}> a.json | |
dump_redis_hash_to_json hoge 100 ${fd} | |
exec {fd}>&- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment