Skip to content

json.set After what can consolidation be supported? #618

Closed

Description

@501956430

`
example:
json.set a . '{"name":"abcd","age":1}'
json.get a result : {"name":"abcd","age":1}

Expected results:
json.set a . '{"type":1}"' or json.merge a . '{"type":1}"'
json.get a result : {"name":"abcd","age":1,"type":1}
`

Activity

  1. oshadmi commented on Jan 14, 2022

    @oshadmi
    Collaborator

    JSON.SET updates a value at a given path, if the path already exists.
    JSON.SET also adds a new immediate child, if the path to the parent already exists.
    For example,

    127.0.0.1:6379> json.set a $ '{"name":"abcd","age":1}'
    OK
    127.0.0.1:6379> json.get a $
    "[{\"name\":\"abcd\",\"age\":1}]"
    

    Adding a new immediate child

    127.0.0.1:6379> json.set a $.type '1'
    OK
    127.0.0.1:6379> json.get a $
    "[{\"name\":\"abcd\",\"age\":1,\"type\":1}]"
    

    Updating existing value

    127.0.0.1:6379> json.set a $.type '2'
    OK
    127.0.0.1:6379> json.get a $
    "[{\"name\":\"abcd\",\"age\":1,\"type\":2}]"
    

    Adding more children

    127.0.0.1:6379>  json.set a $.new_arr '[1,2,3]'
    OK
    127.0.0.1:6379>  json.get a $
    "[{\"name\":\"abcd\",\"age\":1,\"type\":2,\"new_arr\":[1,2,3]}]"
    127.0.0.1:6379> json.set a $.new_obj '{"level2":{"name":"xyz"}}'
    OK
    127.0.0.1:6379> json.get a $
    "[{\"name\":\"abcd\",\"age\":1,\"type\":2,\"new_arr\":[1,2,3],\"new_obj\":{\"level2\":{\"name\":\"xyz\"}}}]"
    127.0.0.1:6379> 
    

    See json.set documentation on NX and XX flags for more controlled consolidation.

  2. 501956430 commented on Jan 17, 2022

    @501956430
    Author

    @oshadmi thank you I hope it can be added to the document

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions