Skip to content

Instantly share code, notes, and snippets.

@arc279
Last active March 15, 2017 08:38
Show Gist options
  • Save arc279/61f2e86e232ca84c1873953dbd927294 to your computer and use it in GitHub Desktop.
Save arc279/61f2e86e232ca84c1873953dbd927294 to your computer and use it in GitHub Desktop.
redis hash dump by hscan
#!/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