rejson = py示例不适用于python 3.6

时间:2018-08-12 02:42:41

标签: python redis rejson

尝试通过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\"}}"

任何帮助得到赞赏。

1 个答案:

答案 0 :(得分:1)

已解决。需要在客户端设置中添加decode_responses:

    $(".btnAddBills").click(function(event) {  
swal.mixin({
    input: 'text',
    confirmButtonText: 'Next →',
    showCancelButton: true,
    progressSteps: ['1', '2', '3']
}).queue([
{
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy'
},
'Question 2',
'Question 3'
]).then((result) => {
    if (result.value) {
        swal({
            title: 'All done!',
            html:
            'Your answers: <pre><code>' +
            JSON.stringify(result.value) +
            '</code></pre>',
            confirmButtonText: 'Lovely!'
        })
    }
})