Interface RedisJsonCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection, DefaultedRedisConnection, RedisClusterConnection, RedisCommands, RedisConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection
JSON commands supported by Redis.
Many methods in this interface return a List rather than a single value. This is because JSONPath expressions
can match multiple values within a document, and each match produces its own result. For example, given the following
document stored at key user:1:
{
"groups": [
{ "name": "admins", "roles": ["read", "write", "delete"] },
{ "name": "editors", "roles": ["read", "write"] },
{ "name": "viewers", "roles": ["read"] }
]
}
Calling JSON.ARRINDEX user:1 $.groups[*].roles "write" returns:
[1, 1, -1]
The path $.groups[*].roles matches three arrays, so the result contains one entry per match: index 1
for the first two arrays (where "write" appears at position 1) and -1 for the third array (where
"write" is not found).- Since:
- 4.2
- Author:
- Yordan Tsintsov, Mark Paluch
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAppend theJSON valueinto the array atJsonPathafter the last element in it.Search for the first occurrence of aJSON valuein an array.jsonArrInsert(byte @NonNull [] key, @NonNull JsonPath path, int index, @NonNull JsonValue @NonNull ... values) jsonArrLen(byte @NonNull [] key, @NonNull JsonPath path) Get the length of the array at the given path.jsonArrTrim(byte @NonNull [] key, @NonNull JsonPath path, int start, int stop) Trim an array so that it contains only the specified inclusive range of elements.default LongClear container values (arrays/objects) and set numeric values to0at the root path of the given key.Clear container values (arrays/objects) and set numeric values to0at the given key and path.default LongDelete theJSON valueat the root path of the given key.Delete theJSON valueat the given key and path.default byte[]Get theJSON valueat the root path of the given key.byte[]Get the JSON values at the given key and paths.Merge theJSON valueat the given key and path.default BooleanMerge theJSON valueat the root path of the givenkey.default List<byte[]> Get the JSON values at the root path of the given keys.List<byte[]> Get the JSON values at the given path for the given keys.jsonSet(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue value, @NonNull JsonSetCondition condition) Set theJSON valueat the given key and path.default BooleanSet theJSON valueat the root path of the given key.Append a string value to the JSON string at the given path.jsonStrLen(byte @NonNull [] key, @NonNull JsonPath path) Get the length of the JSON string value at the given path.jsonToggle(byte @NonNull [] key, @NonNull JsonPath path) Toggle boolean values at the given key and path.Get theJSON typeat the root path of the given key.Get theJSON typeat the given key and path.
-
Method Details
-
jsonArrAppend
List<Long> jsonArrAppend(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue @NonNull ... values) Append theJSON valueinto the array atJsonPathafter the last element in it.- Parameters:
key- must not be null.path- must not be null.values- must not be null.- Returns:
- a list where each element contains the new length of the array or null if the matched value is not an array. Returns an empty list if the path does not match any value.
- See Also:
-
jsonArrIndex
Search for the first occurrence of aJSON valuein an array.- Parameters:
key- must not be null.path- must not be null.value- must not be null.- Returns:
- a list where each element contains the index of the first occurrence of the value,
-1if not found, or null if the matched value is not an array. Returns an empty list if the path does not match any value. - See Also:
-
jsonArrInsert
List<Long> jsonArrInsert(byte @NonNull [] key, @NonNull JsonPath path, int index, @NonNull JsonValue @NonNull ... values) - Parameters:
key- must not be null.path- must not be null.index- to insert before.values- must not be null.- Returns:
- a list where each element contains the new length of the array after the insertion or null if the matched value is not an array. Returns an empty list if the path does not match any value.
- See Also:
-
jsonArrLen
Get the length of the array at the given path.- Parameters:
key- must not be null.path- must not be null.- Returns:
- a list where each element contains the length of the array or null if the matched value is not an array. Returns an empty list if the path does not match any value.
- See Also:
-
jsonArrTrim
Trim an array so that it contains only the specified inclusive range of elements.- Parameters:
key- must not be null.path- must not be null.start- index to start trimming from (inclusive).stop- index to stop trimming at (inclusive).- Returns:
- a list where each element contains the length of the array after the trim or null if the matched value is not an array. Returns an empty list if the path does not match any value.
- See Also:
-
jsonClear
-
jsonClear
-
jsonDel
Delete theJSON valueat the root path of the given key.- Parameters:
key- must not be null.- Returns:
- the number of paths deleted.
- See Also:
-
jsonDel
Delete theJSON valueat the given key and path.- Parameters:
key- must not be null.path- must not be null.- Returns:
- the number of paths deleted.
- See Also:
-
jsonGet
Get theJSON valueat the root path of the given key.- Parameters:
key- must not be null.- Returns:
- a JSON-serialized byte array.
- See Also:
-
jsonGet
Get the JSON values at the given key and paths.- Parameters:
key- must not be null.paths- must not be null.- Returns:
- a JSON-serialized byte array. When a single path is given, returns the value at that path. When multiple paths are given, returns a JSON object with each path as a key. Returns null if the key does not exist.
- See Also:
-
jsonMerge
Merge theJSON valueat the root path of the givenkey.- Parameters:
key- must not be null.value- must not be null.- Returns:
- true if the key was merged, false otherwise.
- See Also:
-
jsonMerge
-
jsonMGet
-
jsonMGet
-
jsonSet
Set theJSON valueat the root path of the given key.- Parameters:
key- must not be null.value- must not be null.- Returns:
- true if the key was set, false otherwise.
- See Also:
-
jsonSet
Boolean jsonSet(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue value, @NonNull JsonSetCondition condition) Set theJSON valueat the given key and path.- Parameters:
key- must not be null.path- must not be null.value- must not be null.condition- must not be null.- Returns:
- true if the key was set, false otherwise.
- See Also:
-
jsonStrAppend
Append a string value to the JSON string at the given path.- Parameters:
key- must not be null.path- must not be null.value- the plain string value, must not be null.- Returns:
- a list where each element is the new string length or null if the matched value is not a string. Returns an empty list if the path does not match any value.
- See Also:
-
jsonStrLen
Get the length of the JSON string value at the given path.- Parameters:
key- must not be null.path- must not be null.- Returns:
- a list where each element is the string length or null if the matched value is not a string. Returns an empty list if the path does not match any value.
- See Also:
-
jsonToggle
Toggle boolean values at the given key and path.- Parameters:
key- must not be null.path- must not be null.- Returns:
- a list where each element is the new boolean value after toggling, or null if the matched value is not a boolean. Returns an empty list if the path does not match any value.
- See Also:
-
jsonType
-
jsonType
-