尝试使用 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\"}}"
感谢任何帮助。
最佳答案
已解决。需要将 decode_responses 添加到客户端设置中:
rj = Client(host='localhost', port=6379, decode_responses=True)
关于python - rejson=py 示例不适用于 python 3.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51805265/