JSON.TOGGLE
Syntax
1. JSON.TOGGLE key path
Time complexity: O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
Toggle a Boolean value stored at path
Required arguments
key
is key to modify.
Optional arguments
path
is JSONPath to specify. Default is root $.
Return
JSON.TOGGLE returns an array of integer replies for each path, the new value (0 if false or 1 if true), or nil for JSON values matching the path that are not Boolean. For more information about replies, see Redis serialization protocol specification.
Examples
Toogle a Boolean value stored at path
Create a JSON document.
1. dragonfly> JSON.SET doc $ '{"bool": true}'
2. OK
Toggle the Boolean value.
1. dragonfly> JSON.TOGGLE doc $.bool
2. 1) (integer) 0
Get the updated document.
1. dragonfly> JSON.GET doc $
2. "[{\"bool\":false}]"
Toggle the Boolean value.
1. dragonfly> JSON.TOGGLE doc $.bool
2. 1) (integer) 1
Get the updated document.
1. dragonfly> JSON.GET doc $
2. "[{\"bool\":true}]"
See also
JSON.SET | JSON.GET
