如何解码redis cli或shell脚本中的值

时间:2017-10-29 04:41:08

标签: bash shell utf-8 redis redis-cli

我编写了redis-cli bash脚本来处理批量检索的所有键和值,但值没有按预期打印。当我用redis-cli给我的密钥打印所有特殊字符:

我的密钥和redis-cli的输出

redis-cli MGET "0124" "0016"
1) "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\x00\x1d\x8e1\x0e\xc3@\b\x04?\x04\x0e8Q\x17\xa9\xf9\xdc\xdeY\x0b2\x91[\xfd>K\x99\xfd\xaf\xfc\x03\xeb-1\x10\xef\x00\x00\x00"
2) "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\x00\x1d\x8e1\x92\x031\b\x04?\x04k\x84\x10\xa0\xf8\x1;\xa8-7\xbb\xa2> \xc0n\xdc\xe1\xce\xdb\xbdk\xac\x81\x9a]Q*\x8ex\xa4\xe0\x99\xd5\xd1\xb3\x94w^\x9f]\xa7$2\xce;\xdcp\x9c\x9b\xff;\xff\x01\xb3\xcc\xd5H\xf0\x00\x00\x00"

有人可以帮助您解决如何在redis-cli或shell脚本中解码此值。 我是Redis的新手 - 如果你能帮助我解决这个问题,我将非常感激

我使用了gunzip - 但我收到了以下错误:

redis-cli -h GET "100" | gunzip

错误:

   gzip: stdin: unexpected end of file
   gzip: stdin: decompression OK, trailing garbage ignored

Redis-cli代码:

#!/bin/sh
hostName=$1
port=$2
count=$3
cursor=-1
keys=""
recordCount=0
while [ $cursor -ne 0 ];
do
        if [ $cursor -eq -1 ]
        then
        cursor=0
    fi
    reply=`redis-cli -h $hostName -p $port SCAN $cursor MATCH "*" COUNT $count`
    cursor=`expr "$reply" : '\([0-9]*[0-9 ]\)'`
    keys=${reply#[0-9]*[[:space:]]}
    value=$(redis-cli -h $hostName -p $port MGET $keys)
    temCount=`echo $value | awk -F\| '{print NF-1}'`
    recordCount=`expr ${temCount} + ${recordCount}`
done
echo "Total no. of documents are: " $recordCount

我的Redis键值模式:

Keys - 123.item.media
Values - 93839,abc,98,829|38282,yiw,282,282|8922,dux,382,993|

Keys - 234.item.media
Values - 2122,eww,92,211|8332,uei,902,872|9039,uns,892,782|

Keys - 839.item.media
Values - 7822,nkp,77,002|7821,mko,999,822|

0 个答案:

没有答案