【问题标题】:rejson=py example not working on python 3.6rejson=py 示例不适用于 python 3.6
【发布时间】:2018-08-12 02:42:41
【问题描述】:

尝试通过 Python3 设置 ReJSON。我在 Windows (WSL) 中的 Ubuntu 16.04 上运行,并且 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

我知道 obj 已经写好了,可以在 redis-cli 中看到:

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

感谢任何帮助。

【问题讨论】:

    标签: python redis redisjson


    【解决方案1】:

    解决了。需要将 decode_responses 添加到客户端设置中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多