Interface ReactiveRedisOperations<K,V>
- All Known Implementing Classes:
ReactiveRedisTemplate
,ReactiveStringRedisTemplate
ReactiveRedisTemplate
. Not often
used but a useful option for extensibility and testability (as it can be easily mocked or stubbed).
Streams of methods returning Mono<K>
or Flux<M>
are terminated with
InvalidDataAccessApiUsageException
when
RedisElementReader.read(ByteBuffer)
returns null
for a
particular element as Reactive Streams prohibit the usage of null
values.
- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Long>
convertAndSend
(String destination, V message) Publishes the given message to the given channel.reactor.core.publisher.Mono<Boolean>
Copy givensourceKey
totargetKey
.reactor.core.publisher.Mono<Long>
Delete givenkey
.reactor.core.publisher.Mono<Long>
Delete givenkeys
.<T> reactor.core.publisher.Flux<T>
execute
(ReactiveRedisCallback<T> action) Executes the given action within a Redis connection.default <T> reactor.core.publisher.Flux<T>
execute
(RedisScript<T> script) Executes the givenRedisScript
.default <T> reactor.core.publisher.Flux<T>
execute
(RedisScript<T> script, List<K> keys) Executes the givenRedisScript
.<T> reactor.core.publisher.Flux<T>
execute
(RedisScript<T> script, List<K> keys, List<?> args) Executes the givenRedisScript
<T> reactor.core.publisher.Flux<T>
execute
(RedisScript<T> script, List<K> keys, List<?> args, RedisElementWriter<?> argsWriter, RedisElementReader<T> resultReader) Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.<T> reactor.core.publisher.Flux<T>
executeInSession
(ReactiveRedisSessionCallback<K, V, T> action) Executes the given action within a Redis session using the sameReactiveRedisConnection
.reactor.core.publisher.Mono<Boolean>
Set time to live for givenkey
.reactor.core.publisher.Mono<Boolean>
Set the expiration for givenkey
as a expireAt timestamp.reactor.core.publisher.Mono<Duration>
Get the time to live forkey
.reactor.core.publisher.Mono<Boolean>
Determine if givenkey
exists.reactor.core.publisher.Flux<K>
Find all keys matching the givenpattern
.reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>> default reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>> listenToChannel
(String... channels) Subscribe to the given Redischannels
and emitmessages
received for those.default reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>>> listenToChannelLater
(String... channels) Subscribe to the given Redischannels
and emitmessages
received for those.reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>>> listenToLater
(Topic... topics) default reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>> listenToPattern
(String... patterns) Subscribe to the Redis channels matching the givenpattern
and emitmessages
received for those.default reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,
V>>> listenToPatternLater
(String... patterns) Subscribe to the Redis channels matching the givenpattern
and emitmessages
received for those.reactor.core.publisher.Mono<Boolean>
Move givenkey
to database withindex
.Returns geospatial specific operations interface.<K,
V> ReactiveGeoOperations<K, V> opsForGeo
(RedisSerializationContext<K, V> serializationContext) Returns geospatial specific operations interface.<HK,
HV> ReactiveHashOperations<K, HK, HV> Returns the operations performed on hash values.<K,
HK, HV> ReactiveHashOperations<K, HK, HV> opsForHash
(RedisSerializationContext<K, ?> serializationContext) Returns the operations performed on hash values given aRedisSerializationContext
.Returns the operations performed on multisets using HyperLogLog.<K,
V> ReactiveHyperLogLogOperations<K, V> opsForHyperLogLog
(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on multisets using HyperLogLog given aRedisSerializationContext
.Returns the operations performed on list values.<K,
V> ReactiveListOperations<K, V> opsForList
(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on list values given aRedisSerializationContext
.Returns the operations performed on set values.<K,
V> ReactiveSetOperations<K, V> opsForSet
(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on set values given aRedisSerializationContext
.<HK,
HV> ReactiveStreamOperations<K, HK, HV> Returns the operations performed on streams.<HK,
HV> ReactiveStreamOperations<K, HK, HV> opsForStream
(HashMapper<? super K, ? super HK, ? super HV> hashMapper) Returns the operations performed on streams.<HK,
HV> ReactiveStreamOperations<K, HK, HV> opsForStream
(RedisSerializationContext<K, ?> serializationContext) Returns the operations performed on streams given aRedisSerializationContext
.Returns the operations performed on simple values (or Strings in Redis terminology).<K,
V> ReactiveValueOperations<K, V> opsForValue
(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on simple values (or Strings in Redis terminology) given aRedisSerializationContext
.Returns the operations performed on zset values (also known as sorted sets).<K,
V> ReactiveZSetOperations<K, V> opsForZSet
(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on zset values (also known as sorted sets) given aRedisSerializationContext
.reactor.core.publisher.Mono<Boolean>
Remove the expiration from givenkey
.reactor.core.publisher.Mono<K>
Return a random key from the keyspace.reactor.core.publisher.Mono<Boolean>
Rename keyoldKey
tonewKey
.reactor.core.publisher.Mono<Boolean>
renameIfAbsent
(K oldKey, K newKey) Rename keyoldKey
tonewKey
only ifnewKey
does not exist.default reactor.core.publisher.Flux<K>
scan()
Use aFlux
to iterate over keys.reactor.core.publisher.Flux<K>
scan
(ScanOptions options) Use aFlux
to iterate over keys.reactor.core.publisher.Mono<DataType>
Determine the type stored atkey
.reactor.core.publisher.Mono<Long>
Unlink thekey
from the keyspace.reactor.core.publisher.Mono<Long>
Unlink thekeys
from the keyspace.
-
Method Details
-
execute
Executes the given action within a Redis connection. Application exceptions thrown by the action object get propagated to the caller (can only be unchecked) whenever possible. Redis exceptions are transformed into appropriate DAO ones. Allows for returning a result object, that is a domain object or a collection of domain objects. Performs automatic serialization/deserialization for the given objects to and from binary data suitable for the Redis storage. Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager. Generally, callback code must not touch any Connection lifecycle methods, like close, to let the template do its work.- Type Parameters:
T
- return type- Parameters:
action
- callback object that specifies the Redis action- Returns:
- a result object returned by the action or
Flux.empty()
.
-
executeInSession
Executes the given action within a Redis session using the sameReactiveRedisConnection
. Application exceptions thrown by the action object get propagated to the caller (can only be unchecked) whenever possible. Redis exceptions are transformed into appropriate DAO ones. Allows for returning a result object, that is a domain object or a collection of domain objects. Performs automatic serialization/deserialization for the given objects to and from binary data suitable for the Redis storage. Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager. Generally, callback code must not touch any Connection lifecycle methods, like close, to let the template do its work.- Type Parameters:
T
- return type- Parameters:
action
- callback object that specifies the Redis action- Returns:
- a result object returned by the action or
Flux.empty()
. - Since:
- 2.6
-
convertAndSend
Publishes the given message to the given channel.- Parameters:
destination
- the channel to publish to, must not be null nor empty.message
- message to publish. Must not be null.- Returns:
- the number of clients that received the message
- Since:
- 2.1
- See Also:
-
listenToChannel
default reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>> listenToChannel(String... channels) Subscribe to the given Redischannels
and emitmessages
received for those.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
channels
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.1
- See Also:
-
listenToPattern
default reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>> listenToPattern(String... patterns) Subscribe to the Redis channels matching the givenpattern
and emitmessages
received for those.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
patterns
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.1
- See Also:
-
listenTo
reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>> listenTo(Topic... topics) Subscribe to the Redis channels for the giventopics
and emitmessages
received for those.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
topics
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.1
- See Also:
-
listenToChannelLater
default reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>>> listenToChannelLater(String... channels) Subscribe to the given Redischannels
and emitmessages
received for those. TheMono
completes once thetopic
subscriptions are registered.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
channels
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.6
- See Also:
-
listenToPatternLater
default reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>>> listenToPatternLater(String... patterns) Subscribe to the Redis channels matching the givenpattern
and emitmessages
received for those. TheMono
completes once thetopic
subscriptions are registered.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
patterns
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.6
- See Also:
-
listenToLater
reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>>> listenToLater(Topic... topics) Subscribe to the Redis channels for the giventopics
and emitmessages
received for those. TheMono
completes once thetopic
subscriptions are registered.Note that this method allocates a new
ReactiveRedisMessageListenerContainer
and uses a dedicated connection, similar to other methods on this interface. Invoking this method multiple times is an indication that you should useReactiveRedisMessageListenerContainer
directly.- Parameters:
topics
- must not be null.- Returns:
- a hot sequence of
messages
. - Since:
- 2.6
- See Also:
-
copy
Copy givensourceKey
totargetKey
.- Parameters:
sourceKey
- must not be null.targetKey
- must not be null.- Returns:
- Since:
- 2.6
- See Also:
-
hasKey
Determine if givenkey
exists.- Parameters:
key
- must not be null.- Returns:
- See Also:
-
type
Determine the type stored atkey
.- Parameters:
key
- must not be null.- Returns:
- See Also:
-
keys
Find all keys matching the givenpattern
.
IMPORTANT: It is recommended to usescan()
to iterate over the keyspace askeys(Object)
is a non-interruptible and expensive Redis operation.- Parameters:
pattern
- must not be null.- Returns:
- the
Flux
emitting matching keys one by one. - Throws:
IllegalArgumentException
- in case the pattern is null.- See Also:
-
scan
Use aFlux
to iterate over keys. The resultingFlux
acts as a cursor and issuesSCAN
commands itself as long as the subscriber signals demand.- Returns:
- the
Flux
emitting the keys one by one or anempty flux
if none exist. - Since:
- 2.1
- See Also:
-
scan
Use aFlux
to iterate over keys. The resultingFlux
acts as a cursor and issuesSCAN
commands itself as long as the subscriber signals demand.- Parameters:
options
- must not be null. UseScanOptions.NONE
instead.- Returns:
- the
Flux
emitting the keys one by one or anempty flux
if none exist. - Throws:
IllegalArgumentException
- when the givenoptions
is null.- Since:
- 2.1
- See Also:
-
randomKey
reactor.core.publisher.Mono<K> randomKey()Return a random key from the keyspace.- Returns:
- See Also:
-
rename
Rename keyoldKey
tonewKey
.- Parameters:
oldKey
- must not be null.newKey
- must not be null.- See Also:
-
renameIfAbsent
Rename keyoldKey
tonewKey
only ifnewKey
does not exist.- Parameters:
oldKey
- must not be null.newKey
- must not be null.- Returns:
- See Also:
-
delete
Delete givenkey
.- Parameters:
key
- must not be null.- Returns:
- The number of keys that were removed.
- See Also:
-
delete
Delete givenkeys
. This command buffers keys received fromPublisher
into chunks of 128 keys to delete to reduce the number of issuedDEL
commands.- Parameters:
keys
- must not be null.- Returns:
- The number of keys that were removed.
- See Also:
-
unlink
Unlink thekey
from the keyspace. Unlike withdelete(Object[])
the actual memory reclaiming here happens asynchronously.- Parameters:
key
- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- Since:
- 2.1
- See Also:
-
unlink
Unlink thekeys
from the keyspace. Unlike withdelete(Publisher)
the actual memory reclaiming here happens asynchronously. This command buffers keys received fromPublisher
into chunks of 128 keys to delete to reduce the number of issuedUNLINK
commands.- Parameters:
keys
- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- Since:
- 2.1
- See Also:
-
expire
Set time to live for givenkey
.- Parameters:
key
- must not be null.timeout
- must not be null.- Returns:
-
expireAt
Set the expiration for givenkey
as a expireAt timestamp.- Parameters:
key
- must not be null.expireAt
- must not be null.- Returns:
-
persist
Remove the expiration from givenkey
.- Parameters:
key
- must not be null.- Returns:
- See Also:
-
move
Move givenkey
to database withindex
.- Parameters:
key
- must not be null.dbIndex
-- Returns:
- See Also:
-
getExpire
Get the time to live forkey
.- Parameters:
key
- must not be null.- Returns:
- the
Duration
of the associated key.Duration.ZERO
if no timeout associated or emptyMono
if the key does not exist. - See Also:
-
execute
Executes the givenRedisScript
.- Parameters:
script
- must not be null.- Returns:
- result value of the script
Flux.empty()
ifRedisScript.getResultType()
is null, likely indicating a throw-away status reply (i.e. "OK").
-
execute
Executes the givenRedisScript
.- Parameters:
script
- must not be null.keys
- must not be null.- Returns:
- result value of the script
Flux.empty()
ifRedisScript.getResultType()
is null, likely indicating a throw-away status reply (i.e. "OK").
-
execute
Executes the givenRedisScript
- Parameters:
script
- The script to execute. Must not be null.keys
- keys that need to be passed to the script. Must not be null.args
- args that need to be passed to the script. Must not be null.- Returns:
- result value of the script
Flux.empty()
ifRedisScript.getResultType()
is null, likely indicating a throw-away status reply (i.e. "OK").
-
execute
<T> reactor.core.publisher.Flux<T> execute(RedisScript<T> script, List<K> keys, List<?> args, RedisElementWriter<?> argsWriter, RedisElementReader<T> resultReader) Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.- Parameters:
script
- The script to executeargsWriter
- TheRedisElementWriter
to use for serializing argsresultReader
- TheRedisElementReader
to use for serializing the script return valuekeys
- keys that need to be passed to the script.args
- args that need to be passed to the script.- Returns:
- result value of the script
Flux.empty()
ifRedisScript.getResultType()
is null, likely indicating a throw-away status reply (i.e. "OK").
-
opsForGeo
ReactiveGeoOperations<K,V> opsForGeo()Returns geospatial specific operations interface.- Returns:
- geospatial specific operations.
-
opsForGeo
Returns geospatial specific operations interface.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- geospatial specific operations.
-
opsForHash
Returns the operations performed on hash values.- Type Parameters:
HK
- hash key (or field) type.HV
- hash value type.- Returns:
- hash operations.
-
opsForHash
<K,HK, ReactiveHashOperations<K,HV> HK, opsForHashHV> (RedisSerializationContext<K, ?> serializationContext) Returns the operations performed on hash values given aRedisSerializationContext
.- Type Parameters:
HK
- hash key (or field) type.HV
- hash value type.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- hash operations.
-
opsForHyperLogLog
ReactiveHyperLogLogOperations<K,V> opsForHyperLogLog()Returns the operations performed on multisets using HyperLogLog.- Returns:
- never null.
-
opsForHyperLogLog
<K,V> ReactiveHyperLogLogOperations<K,V> opsForHyperLogLog(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on multisets using HyperLogLog given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- never null.
-
opsForList
ReactiveListOperations<K,V> opsForList()Returns the operations performed on list values.- Returns:
- list operations.
-
opsForList
Returns the operations performed on list values given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- list operations.
-
opsForSet
ReactiveSetOperations<K,V> opsForSet()Returns the operations performed on set values.- Returns:
- set operations.
-
opsForSet
Returns the operations performed on set values given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- set operations.
-
opsForStream
Returns the operations performed on streams.- Returns:
- stream operations.
- Since:
- 2.2
-
opsForStream
<HK,HV> ReactiveStreamOperations<K,HK, opsForStreamHV> (HashMapper<? super K, ? super HK, ? super HV> hashMapper) Returns the operations performed on streams.- Parameters:
hashMapper
- theHashMapper
to use when mapping complex objects.- Returns:
- stream operations.
- Since:
- 2.2
-
opsForStream
<HK,HV> ReactiveStreamOperations<K,HK, opsForStreamHV> (RedisSerializationContext<K, ?> serializationContext) Returns the operations performed on streams given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- stream operations.
- Since:
- 2.2
-
opsForValue
ReactiveValueOperations<K,V> opsForValue()Returns the operations performed on simple values (or Strings in Redis terminology).- Returns:
- value operations
-
opsForValue
<K,V> ReactiveValueOperations<K,V> opsForValue(RedisSerializationContext<K, V> serializationContext) Returns the operations performed on simple values (or Strings in Redis terminology) given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- value operations.
-
opsForZSet
ReactiveZSetOperations<K,V> opsForZSet()Returns the operations performed on zset values (also known as sorted sets).- Returns:
- zset operations.
-
opsForZSet
Returns the operations performed on zset values (also known as sorted sets) given aRedisSerializationContext
.- Parameters:
serializationContext
- serializers to be used with the returned operations, must not be null.- Returns:
- zset operations.
-
getSerializationContext
RedisSerializationContext<K,V> getSerializationContext()- Returns:
- the
RedisSerializationContext
.
-