小编lea*_*ava的帖子

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

我已经编写了 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"
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙如何在 redis-cli 或 shell 脚本中解码这个值吗?我是 Redis 新手 - 如果您能帮助我解决这个问题,我将不胜感激

我使用了gunzip - 但出现以下错误:

redis-cli -h GET "100" | gunzip
Run Code Online (Sandbox Code Playgroud)

错误:

   gzip: stdin: unexpected end of file
   gzip: stdin: decompression OK, trailing garbage ignored
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

bash shell utf-8 redis redis-cli

10
推荐指数
1
解决办法
6454
查看次数

如何使用python压缩字符串并存储在redis中

我想在 python 中使用带有 GZIP 的 Utf8 字符串编解码器存储我的所有字符串。

我尝试了下面的代码,但压缩没有正确发生。我不知道这里缺少什么。如何使用 gzip 压缩技术将数据插入 redis。

插入 redis 后,它只是打印一些数字,如 d49

import redis
import StringIO
import gzip

r = redis.StrictRedis(host='127.0.0.1', port=80, db=0, decode_responses=True)

out = StringIO.StringIO()
with gzip.GzipFile(fileobj=out, mode='w') as f:
    value = f.write('this is my test value')
    r.set('test', value)
Run Code Online (Sandbox Code Playgroud)

提前感谢您的帮助!

谢谢

python compression redis

5
推荐指数
1
解决办法
1509
查看次数

标签 统计

redis ×2

bash ×1

compression ×1

python ×1

redis-cli ×1

shell ×1

utf-8 ×1