Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion content/commands/json.set/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ sets the key only if it already exists.

## Return value

JSET.SET returns a simple string reply: `OK` if executed correctly or `nil` if the specified `NX` or `XX` conditions were not met.
Returns one of these replies:
- A simple string reply: `OK` if executed correctly
- `nil`
- if `key` exists but `path` does not exist and cannot be created
- if an `NX` or `XX` condition is unmet
- error if `key` does not exist and `path` is not root (`.` or `$`)

For more information about replies, see [Redis serialization protocol specification]({{< relref "/develop/reference/protocol-spec" >}}).

## Examples
Expand Down Expand Up @@ -123,6 +129,38 @@ redis> JSON.GET doc
{{< / highlight >}}
</details>

<details open>
<summary><b>path does not exist and cannot be created</b></summary>

{{< highlight bash >}}
redis> JSON.SET doc $ 1
OK
redis> JSON.SET doc $.x.y 2
(nil)
{{< / highlight >}}
</details>

<details open>
<summary><b>XX condition unmet</b></summary>

{{< highlight bash >}}
redis> JSON.SET nonexistentkey $ 5 XX
(nil)
redis> JSON.GET nonexistentkey
(nil)
{{< / highlight >}}
</details>

<details open>
<summary><b>key does not exist and path is not root</b></summary>

{{< highlight bash >}}
redis> JSON.SET nonexistentkey $.x 5
(error) ERR new objects must be created at the root
{{< / highlight >}}
</details>


## See also

[`JSON.GET`]({{< baseurl >}}/commands/json.get/) | [`JSON.MGET`]({{< baseurl >}}/commands/json.mget/)
Expand Down
Loading