Redis reJson:JSON.ARRAYAPPEND针对持有错误值的键返回WRONGTYPE操作

问题描述 投票:0回答:1

在redis-rejson上我试图计算一个arrayappend。我放入了一个对象,一个路径,一个json和一个数组,如documentation所示。

简要:

我的目标=>我想用Redis创建一个对象数组

我的目标=>该对象数组允许我将用户会话放入我的redis缓存中

我的desserated输出=> " [{objectOne}, {objectTwoJustAdded}]"

我的问题=>好像我把错误的类型放在控制台中。

这是我的命令:

   JSON.ARRAPPEND test36 "." '{"user1":"1"}' [... CartModel]
    WRONGTYPE Operation against a key holding the wrong kind of value

但是你可以看到它不起作用,我尝试了一些变化:

    127.0.0.1:6380> JSON.ARRAPPEND test36 "." '{"user1":"1"}'
    WRONGTYPE Operation against a key holding the wrong kind of value

    127.0.0.1:6380> JSON.ARRAPPEND test36 "here a vlue"
    ERR wrong number of arguments for 'JSON.ARRAPPEND' command

    127.0.0.1:6380> JSON.ARRAPPEND test36 "." 'here a value'
    WRONGTYPE Operation against a key holding the wrong kind of value

    127.0.0.1:6380> JSON.ARRAPPEND test36 "." '["here a value"]'
    WRONGTYPE Operation against a key holding the wrong kind of value

    127.0.0.1:6380> JSON.arrappend test36 "."  [ 'example', '.', '{"firstname":"Jon","lastname":"Doe"}' ] 
    Invalid argument(s)
    127.0.0.1:6380> JSON.get CartModel
    {"userID":{"beverage":{},"sandwich":{},"treat":{},"dessert":{}}}
    127.0.0.1:6380> JSON.ARRAPPEND test36 "." '{"user1":"1"}' [... CartModel]
    WRONGTYPE Operation against a key holding the wrong kind of value

    127.0.0.1:6380> JSON.ARRAPPEND arr . 0
    WRONGTYPE Operation against a key holding the wrong kind of value

既不起作用。那怎么办?任何提示都会很棒,谢谢

arrays object redis append command-line-interface
1个回答
0
投票

您必须先在数据库中提供一个数组,然后将其用作其他Json对象的接收者:

127.0.0.1:6380> JSON.set objectArray "." "[]"
OK
127.0.0.1:6380> json.arrappend objectArray "." '{"appenda":"a value"}'
1
127.0.0.1:6380> json.get objectArray
[{"appenda":"a value"}]

PS:为什么程序员喜欢制作模糊的文档?这就像一顿拒绝被吃掉的诱人餐。

© www.soinside.com 2019 - 2024. All rights reserved.