Skip to content

Commit be78df5

Browse files
authored
JSON.SET - clarify return value; more examples
1 parent 2bf3225 commit be78df5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

content/commands/json.set/index.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ sets the key only if it already exists.
7979

8080
## Return value
8181

82-
JSET.SET returns a simple string reply: `OK` if executed correctly or `nil` if the specified `NX` or `XX` conditions were not met.
82+
Returns one of these replies:
83+
- A simple string reply: `OK` if executed correctly
84+
- `nil` - if `path` does not exist and cannot be created, or if the specified `NX` or `XX` conditions were unmet
85+
- error if `key` does not exist and `path` is not root
86+
8387
For more information about replies, see [Redis serialization protocol specification]({{< relref "/develop/reference/protocol-spec" >}}).
8488

8589
## Examples
@@ -123,6 +127,38 @@ redis> JSON.GET doc
123127
{{< / highlight >}}
124128
</details>
125129

130+
<details open>
131+
<summary><b>path does not exist and cannot be created</b></summary>
132+
133+
{{< highlight bash >}}
134+
redis> JSON.SET doc $ 1
135+
OK
136+
redis> JSON.SET doc $.x.y 2
137+
(nil)
138+
{{< / highlight >}}
139+
</details>
140+
141+
<details open>
142+
<summary><b>XX condition unmet</b></summary>
143+
144+
{{< highlight bash >}}
145+
redis> JSON.SET nonexistentkey $ 5 XX
146+
(nil)
147+
redis> JSON.GET nonexistentkey
148+
(nil)
149+
{{< / highlight >}}
150+
</details>
151+
152+
<details open>
153+
<summary><b>key does not exist and path is not root</b></summary>
154+
155+
{{< highlight bash >}}
156+
redis> JSON.SET nonexistentkey $.x 5
157+
(error) ERR new objects must be created at the root
158+
{{< / highlight >}}
159+
</details>
160+
161+
126162
## See also
127163

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

0 commit comments

Comments
 (0)