#/bin/sh
zset_pattern=」*_010_09/Dec/2015″
keys=`redis-cli keys $zset_pattern`
for k in $keys;doredis_date=`echo 「$k」|awk -F」_」 ‘{print $3}’|awk -F」/」 ‘{print $3″_」$2″_」$1}’`
out=`echo 「$k」|awk -F」_」 ‘{print $1″_」$2}’`」_$_date.txt」
cursor=0shellbatches=0
while [ 1==1 ];dospareply=`redis-cli zscan $k $cursor`
cursor=`echo 「$reply」 | head -n 1`ippairs=`echo 「$reply」|tail -n +2`get
[ $cursor -eq 0 ] && [ $batches -gt 0 ] && break
batches=`expr $batches + 1`it
skip_key=0
echo 「$pairs」|while read msclassdoawk
#skip empty members
[ 「$ms」 == 「」 ] && skip_key=1 && continue
[ $skip_key -eq 1 ] && skip_key=0 && continue
if [ 「$m」 == 「」 ];thenclim=$ms && continuedate
fi
if [ 「$s」 == 「」 ];thens=$ms
echo 「$m $s」 >> $out
m=」」 && s=」」fi
done
done
done
零一積流|IT參考 原創文章,轉載請註明出處: http://www.it-refer.com/2015/12/14/a-shell-script-to-export-data-of-sorted-sets-from-redis