rejson=py示例在Python 3.6上无法运行。

3
尝试在Python3中设置ReJSON,我在Windows的Ubuntu 16.04(WSL)上运行,并且Redis和ReJSON都可以运行。已简化了https://github.com/RedisLabs/rejson-py文档中的Python代码以隔离问题。
from rejson import Client, Path

rj = Client(host='localhost', port=6379)

obj = {
    'answer': 42,
    'arr': [None, True, 3.14],
    'truth': {
        'coord': 'out there'
    }
}
rj.jsonset('obj', Path.rootPath(), obj)

temp = rj.jsonget('obj', Path('.truth.coord'))

最后一行出现了错误:
TypeError: cannot use a string pattern on a bytes-like object

我知道该对象已被写入,可以在redis-cli中看到:

127.0.0.1:6379> JSON.GET obj
"{\"answer\":42,\"arr\":[null,true,3.1400000000000001],\"truth\":{\"coord\":\"out there\"}}"

任何帮助都是受欢迎的。
1个回答

4
解决了。需要在客户端设置中添加decode_responses:
rj = Client(host='localhost', port=6379, decode_responses=True)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接