Set the JSON value at path
in key
key
is key to modify.
value
is value to set at the specified path
path
is JSONPath to specify. Default is root $
. For new Redis keys the path
must be the root. For existing keys, when the entire path
exists, the value that it contains is replaced with the json
value. For existing keys, when the path
exists, except for the last element, a new child is added with the json
value.
Adds a key (with its respective value) to a JSON Object (in a RedisJSON data type key) only if it is the last child in the path
, or it is the parent of a new child being added in the path
. Optional arguments NX
and XX
modify this behavior for both new RedisJSON data type keys as well as the JSON Object keys in them.
NX
sets the key only if it does not already exist.
XX
sets the key only if it already exists.
JSET.SET returns a simple string reply: OK
if executed correctly or nil
if the specified NX
or XX
conditions were not met.
For more information about replies, see Redis serialization protocol specification.
Replace an existing value
{{< highlight bash >}}
127.0.0.1:6379> JSON.SET doc $ '{"a":2}'
OK
127.0.0.1:6379> JSON.SET doc
Add a new value
{{< highlight bash >}}
127.0.0.1:6379> JSON.SET doc $ '{"a":2}'
OK
127.0.0.1:6379> JSON.SET doc
Update multi-paths
{{< highlight bash >}} 127.0.0.1:6379> JSON.SET doc $ '{"f1": {"a":1}, "f2":{"a":2}}' OK 127.0.0.1:6379> JSON.SET doc $..a 3 OK 127.0.0.1:6379> JSON.GET doc "{"f1":{"a":3},"f2":{"a":3}}" {{< / highlight >}}
JSON.GET
| JSON.MGET