Class RedisJsonTemplate<K>
- Type Parameters:
K- the Redis key type.
- All Implemented Interfaces:
JsonOperations<K>, RedisJsonOperations<K>
Typed entry points bound to a key allow configuring the command and running it by calling a terminal method returning the command result, for example:
operations.value("key").set("value");
operations.value("key").path("$..name").setIfAbsent("Doe");
operations.array("key").path("$.names").index(2).insert("John");
Person person = operations.value("key").get().as(Person.class);
JSON path expressions follow the
RedisJSON version 2 path
syntax. Unless specified otherwise, results are positionally correlated to matching paths: each element in the
returned List corresponds to a matching path, with null indicating that the matched value has an
incompatible JSON type.
Specification objects are immutable and can be used to build up complex queries.
- Since:
- 4.2
- Author:
- Yordan Tsintsov, Mark Paluch, Moritz Halbritter
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface JsonOperations
JsonOperations.JsonArrayAtIndex, JsonOperations.JsonArraySpec, JsonOperations.JsonAtKeySpec, JsonOperations.JsonAtKeysSpec, JsonOperations.JsonBooleanSpec, JsonOperations.JsonKeySupport<P>, JsonOperations.JsonMultiGetSpec, JsonOperations.JsonPathResult, JsonOperations.JsonResult, JsonOperations.JsonResults, JsonOperations.JsonSet<T,S>, JsonOperations.JsonSetSpec, JsonOperations.JsonStringSpec, JsonOperations.PathSpec<P> Nested classes/interfaces inherited from interface RedisJsonOperations
RedisJsonOperations.KeyDeleteSpec, RedisJsonOperations.KeysDeleteSpec, RedisJsonOperations.KeySpec, RedisJsonOperations.KeysSpec -
Constructor Summary
ConstructorsConstructorDescriptionRedisJsonTemplate(RedisConnectionFactory connectionFactory, RedisSerializer<K> keySerializer, RedisJsonSerializer jsonSerializer) Creates a newRedisJsonTemplateusing the givenRedisConnectionFactoryand serializers. -
Method Summary
Modifier and TypeMethodDescriptionStart building a JSON array operation for the givenkey.Start building a JSON boolean operation for the givenkey.static RedisJsonTemplate<String> create(RedisConnectionFactory connectionFactory) Create a newRedisJsonTemplateusing the givenRedisConnectionFactoryand default serializers for usage withStringkeys.static RedisJsonTemplate<String> create(RedisConnectionFactory connectionFactory, RedisJsonSerializer jsonSerializer) Create a newRedisJsonTemplateusing the givenRedisConnectionFactoryandRedisJsonSerializerfor usage withStringkeys.Delete givenkey.Start building a key-bound operation for the givenkey.keys(Collection<K> keys) Start building a key-bound operation for the givenkeys.paths(K key, Collection<String> paths) Read the values at the given paths for a single key in oneJSON.GETcommand.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.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RedisJsonOperations
keys
-
Constructor Details
-
RedisJsonTemplate
public RedisJsonTemplate(RedisConnectionFactory connectionFactory, RedisSerializer<K> keySerializer, RedisJsonSerializer jsonSerializer) Creates a newRedisJsonTemplateusing the givenRedisConnectionFactoryand serializers.- Parameters:
connectionFactory- must not be null.keySerializer- must not be null.jsonSerializer- must not be null.
-
-
Method Details
-
create
Create a newRedisJsonTemplateusing the givenRedisConnectionFactoryand default serializers for usage withStringkeys.- Parameters:
connectionFactory- the connection factory to use.- Returns:
- a new
RedisJsonTemplateinstance. - See Also:
-
create
public static RedisJsonTemplate<String> create(RedisConnectionFactory connectionFactory, RedisJsonSerializer jsonSerializer) Create a newRedisJsonTemplateusing the givenRedisConnectionFactoryandRedisJsonSerializerfor usage withStringkeys.- Parameters:
connectionFactory- the connection factory to use.jsonSerializer- the JSON serializer to use.- Returns:
- a new
RedisJsonTemplateinstance. - See Also:
-
array
Description copied from interface:JsonOperationsStart building a JSON array operation for the givenkey.- Specified by:
arrayin interfaceJsonOperations<K>- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the array operation.
-
bool
Description copied from interface:JsonOperationsStart building a JSON boolean operation for the givenkey.- Specified by:
boolin interfaceJsonOperations<K>- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the boolean operation.
-
string
Description copied from interface:JsonOperationsStart building a JSON string operation for the givenkey.- Specified by:
stringin interfaceJsonOperations<K>- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the string operation.
-
value
Description copied from interface:JsonOperationsStart building a JSON value operation for the givenkey.- Specified by:
valuein interfaceJsonOperations<K>- Parameters:
key- the Redis key.- Returns:
- a spec for specifying the value operation.
-
paths
Description copied from interface:JsonOperationsRead 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.- Specified by:
pathsin interfaceJsonOperations<K>- 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.
- See Also:
-
values
Description copied from interface:JsonOperationsStart building a JSON read operation for the given keys.- Specified by:
valuesin interfaceJsonOperations<K>- Parameters:
keys- the Redis keys.- Returns:
- a specification for selecting the path to read.
- See Also:
-
key
Description copied from interface:RedisJsonOperationsStart building a key-bound operation for the givenkey.- Specified by:
keyin interfaceRedisJsonOperations<K>- Parameters:
key- must not be null.- Returns:
- a spec for specifying the key-bound operation.
-
keys
Description copied from interface:RedisJsonOperationsStart building a key-bound operation for the givenkeys.- Specified by:
keysin interfaceRedisJsonOperations<K>- Parameters:
keys- must not be null.- Returns:
- a spec for specifying the key-bound operation.
-
delete
Description copied from interface:RedisJsonOperationsDelete givenkey.- Specified by:
deletein interfaceRedisJsonOperations<K>- Parameters:
key- must not be null.- Returns:
- true if the key was removed.
- See Also:
-