Interface JsonOperations<K>
- Type Parameters:
K- the Redis key type.
- All Known Subinterfaces:
RedisJsonOperations<K>
- All Known Implementing Classes:
RedisJsonTemplate
Use the value(Object), array(Object), string(Object), and bool(Object) entry
points to select a key and configure an operation. Commands operate on the document root unless a JSON path is
selected. The following example stores a document and reads one of its properties:
operations.value("user").set(new Person("John", "Doe"));
String firstName = operations.value("user").path("$.firstName").get().as(String.class);
JSON paths follow the RedisJSON
version 2 syntax. Commands returning a List of per-path results preserve the order of the matches. Unless
specified otherwise, a null element indicates an incompatible JSON type.
Operations execute when a command method such as JsonOperations.JsonKeySupport.get() or JsonOperations.JsonSet.set(Object) is
called. Key and path specifications are immutable and can be reused. Use JsonOperations.JsonResult to access a read result
as JSON or deserialize it into a Java object.
- Since:
- 4.2
- Author:
- Mark Paluch, Yordan Tsintsov, Moritz Halbritter
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSpecification for JSON array operations bound to a previously selected array index.static interfaceSpecification for JSON array operations bound to a particularkey.static interfaceSpecification for JSON value operations bound to a particularkey.static interfaceSpecification for JSON multi-key operations sharing a common JSON path.static interfaceSpecification for JSON boolean operations bound to a particularkey.static interfaceCommon support for JSON operations bound to a single key and configurable path.static interfaceTerminal step for executing a JSON read operation across multiple keys.static interfaceCombined result of reading several paths from a single JSON document.static interfaceThe result of a JSON command, with access to its JSON representation and deserialized value.static interfaceA sequence of JSON results with access to their JSON representations and deserialized values.static interfaceJsonOperations.JsonSet<T, S extends JsonOperations.JsonSet<T,S>> Common support for setting JSON values at the currently configured path.static interfaceMutable configuration of the condition for aJSON.SEToperation.static interfaceSpecification for JSON string operations bound to a particularkey.static interfaceJsonOperations.PathSpec<P extends JsonOperations.PathSpec<P>>Common support for selecting the JSON path against which commands operate. -
Method Summary
Modifier and TypeMethodDescriptionStart building a JSON array operation for the givenkey.Start building a JSON boolean operation for the givenkey.default JsonOperations.JsonResultRetrieve the JSON value for the givenkey.default JsonOperations.JsonPathResultRead the values at the given paths for a single key in oneJSON.GETcommand.paths(K key, Collection<String> paths) Read the values at the given paths for a single key in oneJSON.GETcommand.default BooleanSet thekeyto a JSONvalue.Start building a JSON string operation for the givenkey.Start building a JSON value operation for the givenkey.values(Collection<K> keys) Start building a JSON read operation for the given keys.default JsonOperations.JsonAtKeysSpecStart building a JSON read operation for the givenkey.default JsonOperations.JsonAtKeysSpecStart building a JSON read operation for the given keys.
-
Method Details
-
array
Start building a JSON array operation for the givenkey.- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the array operation.
-
bool
Start building a JSON boolean operation for the givenkey.- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the boolean operation.
-
string
Start building a JSON string operation for the givenkey.- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the string operation.
-
value
Start building a JSON value operation for the givenkey.- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the value operation.
-
get
Retrieve the JSON value for the givenkey.- Parameters:
key- the Redis key.- Returns:
- the JSON value for the given key.
-
set
-
paths
Read the values at the given paths for a single key in oneJSON.GETcommand.See
paths(Object, Collection)for supported path forms and result mapping.- Parameters:
key- the Redis key.paths- the paths to read, must not be empty or contain duplicates.- Returns:
- the combined result for the requested paths.
- Throws:
IllegalArgumentException- if the paths violate the requirements ofpaths(Object, Collection).- See Also:
-
paths
Read the values at the given paths for a single key in oneJSON.GETcommand.Paths may be property paths such as
"name"and"address.city", or JSONPath expressions such as"$.name". All paths in a request must use the same form.The result supports
deserializationinto an object with one property per requested path. Property names correspond to the supplied path strings. UseJsonOperations.JsonPathResult.path(String)to access the matches for an individual path.- Parameters:
key- the Redis key.paths- the paths to read, must not be empty or contain duplicates.- Returns:
- the combined result for the requested paths.
- Throws:
IllegalArgumentException- if the paths are empty, contain duplicates, mix property paths with JSONPath expressions, or include a path omitted from the Redis response.- See Also:
-
values
Start building a JSON read operation for the givenkey.- Parameters:
key- the Redis key.- Returns:
- a specification for selecting the path to read.
- See Also:
-
values
Start building a JSON read operation for the given keys.- Parameters:
key- the Redis key.additionalKeys- the additional Redis keys.- Returns:
- a specification for selecting the path to read.
- See Also:
-
values
Start building a JSON read operation for the given keys.- Parameters:
keys- the Redis keys.- Returns:
- a specification for selecting the path to read.
- See Also:
-