Interface ReactiveRedisOperations<K,V>

All Known Implementing Classes:
ReactiveRedisTemplate, ReactiveStringRedisTemplate

public interface ReactiveRedisOperations<K,V>
Interface that specified a basic set of Redis operations, implemented by 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 Details

    • execute

      <T> reactor.core.publisher.Flux<T> execute(ReactiveRedisCallback<T> action)
      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

      <T> reactor.core.publisher.Flux<T> executeInSession(ReactiveRedisSessionCallback<K,V,T> action)
      Executes the given action within a Redis session using the same ReactiveRedisConnection. 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

      reactor.core.publisher.Mono<Long> convertAndSend(String destination, V message)
      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 Redis channels and emit messages received for those.
      Parameters:
      channels - must not be null.
      Returns:
      a hot sequence of messages.
      Since:
      2.1
    • listenToPattern

      default reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>> listenToPattern(String... patterns)
      Subscribe to the Redis channels matching the given pattern and emit messages received for those.
      Parameters:
      patterns - must not be null.
      Returns:
      a hot sequence of messages.
      Since:
      2.1
    • listenTo

      reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>> listenTo(Topic... topics)
      Subscribe to the Redis channels for the given topics and emit messages received for those.
      Parameters:
      topics - must not be null.
      Returns:
      a hot sequence of messages.
      Since:
      2.1
    • listenToChannelLater

      default reactor.core.publisher.Mono<reactor.core.publisher.Flux<? extends ReactiveSubscription.Message<String,V>>> listenToChannelLater(String... channels)
      Subscribe to the given Redis channels and emit messages received for those. The Mono completes once the topic subscriptions are registered.
      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 given pattern and emit messages received for those. The Mono completes once the topic subscriptions are registered.
      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 given topics and emit messages received for those. The Mono completes once the topic subscriptions are registered.
      Parameters:
      topics - must not be null.
      Returns:
      a hot sequence of messages.
      Since:
      2.6
      See Also:
    • copy

      reactor.core.publisher.Mono<Boolean> copy(K sourceKey, K targetKey, boolean replace)
      Copy given sourceKey to targetKey.
      Parameters:
      sourceKey - must not be null.
      targetKey - must not be null.
      Returns:
      Since:
      2.6
      See Also:
    • hasKey

      reactor.core.publisher.Mono<Boolean> hasKey(K key)
      Determine if given key exists.
      Parameters:
      key - must not be null.
      Returns:
      See Also:
    • type

      reactor.core.publisher.Mono<DataType> type(K key)
      Determine the type stored at key.
      Parameters:
      key - must not be null.
      Returns:
      See Also:
    • keys

      reactor.core.publisher.Flux<K> keys(K pattern)
      Find all keys matching the given pattern.
      IMPORTANT: It is recommended to use scan() to iterate over the keyspace as keys(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

      default reactor.core.publisher.Flux<K> scan()
      Use a Flux to iterate over keys. The resulting Flux acts as a cursor and issues SCAN commands itself as long as the subscriber signals demand.
      Returns:
      the Flux emitting the keys one by one or an empty flux if none exist.
      Since:
      2.1
      See Also:
    • scan

      reactor.core.publisher.Flux<K> scan(ScanOptions options)
      Use a Flux to iterate over keys. The resulting Flux acts as a cursor and issues SCAN commands itself as long as the subscriber signals demand.
      Parameters:
      options - must not be null. Use ScanOptions.NONE instead.
      Returns:
      the Flux emitting the keys one by one or an empty flux if none exist.
      Throws:
      IllegalArgumentException - when the given options 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

      reactor.core.publisher.Mono<Boolean> rename(K oldKey, K newKey)
      Rename key oldKey to newKey.
      Parameters:
      oldKey - must not be null.
      newKey - must not be null.
      See Also:
    • renameIfAbsent

      reactor.core.publisher.Mono<Boolean> renameIfAbsent(K oldKey, K newKey)
      Rename key oldKey to newKey only if newKey does not exist.
      Parameters:
      oldKey - must not be null.
      newKey - must not be null.
      Returns:
      See Also:
    • delete

      reactor.core.publisher.Mono<Long> delete(K... key)
      Delete given key.
      Parameters:
      key - must not be null.
      Returns:
      The number of keys that were removed.
      See Also:
    • delete

      reactor.core.publisher.Mono<Long> delete(org.reactivestreams.Publisher<K> keys)
      Delete given keys. This command buffers keys received from Publisher into chunks of 128 keys to delete to reduce the number of issued DEL commands.
      Parameters:
      keys - must not be null.
      Returns:
      The number of keys that were removed.
      See Also:
    • unlink

      reactor.core.publisher.Mono<Long> unlink(K... key)
      Unlink the key from the keyspace. Unlike with delete(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

      reactor.core.publisher.Mono<Long> unlink(org.reactivestreams.Publisher<K> keys)
      Unlink the keys from the keyspace. Unlike with delete(Publisher) the actual memory reclaiming here happens asynchronously. This command buffers keys received from Publisher into chunks of 128 keys to delete to reduce the number of issued UNLINK 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

      reactor.core.publisher.Mono<Boolean> expire(K key, Duration timeout)
      Set time to live for given key.
      Parameters:
      key - must not be null.
      timeout - must not be null.
      Returns:
    • expireAt

      reactor.core.publisher.Mono<Boolean> expireAt(K key, Instant expireAt)
      Set the expiration for given key as a expireAt timestamp.
      Parameters:
      key - must not be null.
      expireAt - must not be null.
      Returns:
    • persist

      reactor.core.publisher.Mono<Boolean> persist(K key)
      Remove the expiration from given key.
      Parameters:
      key - must not be null.
      Returns:
      See Also:
    • move

      reactor.core.publisher.Mono<Boolean> move(K key, int dbIndex)
      Move given key to database with index.
      Parameters:
      key - must not be null.
      dbIndex -
      Returns:
      See Also:
    • getExpire

      reactor.core.publisher.Mono<Duration> getExpire(K key)
      Get the time to live for key.
      Parameters:
      key - must not be null.
      Returns:
      the Duration of the associated key. Duration.ZERO if no timeout associated or empty Mono if the key does not exist.
      See Also:
    • execute

      default <T> reactor.core.publisher.Flux<T> execute(RedisScript<T> script)
      Executes the given RedisScript.
      Parameters:
      script - must not be null.
      Returns:
      result value of the script Flux.empty() if RedisScript.getResultType() is null, likely indicating a throw-away status reply (i.e. "OK").
    • execute

      default <T> reactor.core.publisher.Flux<T> execute(RedisScript<T> script, List<K> keys)
      Executes the given RedisScript.
      Parameters:
      script - must not be null.
      keys - must not be null.
      Returns:
      result value of the script Flux.empty() if RedisScript.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)
      Executes the given RedisScript
      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() if RedisScript.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 given RedisScript, using the provided RedisSerializers to serialize the script arguments and result.
      Parameters:
      script - The script to execute
      argsWriter - The RedisElementWriter to use for serializing args
      resultReader - The RedisElementReader to use for serializing the script return value
      keys - 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() if RedisScript.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

      <K, V> ReactiveGeoOperations<K,V> opsForGeo(RedisSerializationContext<K,V> serializationContext)
      Returns geospatial specific operations interface.
      Parameters:
      serializationContext - serializers to be used with the returned operations, must not be null.
      Returns:
      geospatial specific operations.
    • opsForHash

      <HK, HV> ReactiveHashOperations<K,HK,HV> 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, HV> ReactiveHashOperations<K,HK,HV> opsForHash(RedisSerializationContext<K,?> serializationContext)
      Returns the operations performed on hash values given a RedisSerializationContext.
      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 a RedisSerializationContext.
      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

      <K, V> ReactiveListOperations<K,V> opsForList(RedisSerializationContext<K,V> serializationContext)
      Returns the operations performed on list values given a RedisSerializationContext.
      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

      <K, V> ReactiveSetOperations<K,V> opsForSet(RedisSerializationContext<K,V> serializationContext)
      Returns the operations performed on set values given a RedisSerializationContext.
      Parameters:
      serializationContext - serializers to be used with the returned operations, must not be null.
      Returns:
      set operations.
    • opsForStream

      <HK, HV> ReactiveStreamOperations<K,HK,HV> opsForStream()
      Returns the operations performed on streams.
      Returns:
      stream operations.
      Since:
      2.2
    • opsForStream

      <HK, HV> ReactiveStreamOperations<K,HK,HV> opsForStream(HashMapper<? super K,? super HK,? super HV> hashMapper)
      Returns the operations performed on streams.
      Parameters:
      hashMapper - the HashMapper to use when mapping complex objects.
      Returns:
      stream operations.
      Since:
      2.2
    • opsForStream

      <HK, HV> ReactiveStreamOperations<K,HK,HV> opsForStream(RedisSerializationContext<K,?> serializationContext)
      Returns the operations performed on streams given a RedisSerializationContext.
      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 a RedisSerializationContext.
      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

      <K, V> ReactiveZSetOperations<K,V> opsForZSet(RedisSerializationContext<K,V> serializationContext)
      Returns the operations performed on zset values (also known as sorted sets) given a RedisSerializationContext.
      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.