Class RedisModulesClient

java.lang.Object
io.lettuce.core.AbstractRedisClient
io.lettuce.core.RedisClient
com.redis.lettucemod.RedisModulesClient
All Implemented Interfaces:
AutoCloseable

public class RedisModulesClient extends io.lettuce.core.RedisClient
A scalable and thread-safe client for Redis Modules supporting synchronous, asynchronous and reactive execution models. Multiple threads may share one connection if they avoid blocking and transactional operations such as BLPOP and MULTI/EXEC.

RedisModulesClient can be used with:

  • Redis Standalone

RedisModulesClient is an expensive resource. It holds a set of netty's EventLoopGroup's that use multiple threads. Reuse this instance as much as possible or share a ClientResources instance amongst multiple client instances.

Author:
Julien Ruaux
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final io.lettuce.core.ClientOptions
     
    static final io.lettuce.core.protocol.ProtocolVersion
     

    Fields inherited from class io.lettuce.core.AbstractRedisClient

    channels, closeableResources, connectionEvents
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a uri-less RedisModulesClient.
    protected
    RedisModulesClient(io.lettuce.core.resource.ClientResources clientResources, io.lettuce.core.RedisURI redisURI)
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    Open a new connection to a Redis server that treats keys and values as UTF-8 strings.
    connect(io.lettuce.core.codec.RedisCodec<K,V> codec)
    Open a new connection to a Redis server.
    connect(io.lettuce.core.codec.RedisCodec<K,V> codec, io.lettuce.core.RedisURI redisURI)
    Open a new connection to a Redis server using the supplied RedisURI and the supplied codec to encode/decode keys.
    connect(io.lettuce.core.RedisURI redisURI)
    Open a new connection to a Redis server using the supplied RedisURI that treats keys and values as UTF-8 strings.
    Creates a uri-less RedisModulesClient with default ClientResources.
    create(io.lettuce.core.RedisURI redisURI)
    Create a new client that connects to the supplied uri with default ClientResources.
    create(io.lettuce.core.resource.ClientResources clientResources)
    Creates a uri-less RedisModulesClient with shared ClientResources.
    create(io.lettuce.core.resource.ClientResources clientResources, io.lettuce.core.RedisURI redisURI)
    Create a new client that connects to the supplied uri with shared ClientResources.
    create(io.lettuce.core.resource.ClientResources clientResources, String uri)
    Create a new client that connects to the supplied uri with shared ClientResources.You need to shut down the ClientResources upon shutting down your application.
    Create a new client that connects to the supplied uri with default ClientResources.
    static <B extends io.lettuce.core.ClientOptions.Builder>
    B
     
    protected <K, V> StatefulRedisModulesConnectionImpl<K,V>
    newStatefulRedisConnection(io.lettuce.core.RedisChannelWriter channelWriter, io.lettuce.core.protocol.PushHandler pushHandler, io.lettuce.core.codec.RedisCodec<K,V> codec, Duration timeout)
    Create a new instance of StatefulRedisModulesConnectionImpl or a subclass.
     

    Methods inherited from class io.lettuce.core.RedisClient

    connectAsync, connectPubSub, connectPubSub, connectPubSub, connectPubSub, connectPubSubAsync, connectSentinel, connectSentinel, connectSentinel, connectSentinel, connectSentinelAsync, getSocketAddress, newStatefulRedisPubSubConnection, newStatefulRedisSentinelConnection, newStringStringCodec, setOptions

    Methods inherited from class io.lettuce.core.AbstractRedisClient

    addListener, addListener, channelType, close, connectionBuilder, connectionBuilder, createHandshake, getChannelCount, getCommandListeners, getConnection, getConnection, getDefaultTimeout, getOptions, getResourceCount, getResources, initializeChannelAsync, removeListener, removeListener, setDefaultTimeout, setDefaultTimeout, shutdown, shutdown, shutdown, shutdownAsync, shutdownAsync

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_PROTOCOL_VERSION

      public static final io.lettuce.core.protocol.ProtocolVersion DEFAULT_PROTOCOL_VERSION
    • DEFAULT_CLIENT_OPTIONS

      public static final io.lettuce.core.ClientOptions DEFAULT_CLIENT_OPTIONS
  • Constructor Details

    • RedisModulesClient

      protected RedisModulesClient(io.lettuce.core.resource.ClientResources clientResources, io.lettuce.core.RedisURI redisURI)
    • RedisModulesClient

      protected RedisModulesClient()
      Creates a uri-less RedisModulesClient. You can connect to different Redis servers but you must supply a RedisURI on connecting. Methods without having a RedisURI will fail with a IllegalStateException. Non-private constructor to make RedisModulesClient proxyable.
  • Method Details

    • defaultClientOptions

      public static <B extends io.lettuce.core.ClientOptions.Builder> B defaultClientOptions(B builder)
    • create

      public static RedisModulesClient create()
      Creates a uri-less RedisModulesClient with default ClientResources. You can connect to different Redis servers but you must supply a RedisURI on connecting. Methods without having a RedisURI will fail with a IllegalStateException.
      Returns:
      a new instance of RedisModulesClient
    • create

      public static RedisModulesClient create(io.lettuce.core.RedisURI redisURI)
      Create a new client that connects to the supplied uri with default ClientResources. You can connect to different Redis servers but you must supply a RedisURI on connecting.
      Parameters:
      redisURI - the Redis URI, must not be null
      Returns:
      a new instance of RedisModulesClient
    • create

      public static RedisModulesClient create(String uri)
      Create a new client that connects to the supplied uri with default ClientResources. You can connect to different Redis servers but you must supply a RedisURI on connecting.
      Parameters:
      uri - the Redis URI, must not be null
      Returns:
      a new instance of RedisModulesClient
    • create

      public static RedisModulesClient create(io.lettuce.core.resource.ClientResources clientResources)
      Creates a uri-less RedisModulesClient with shared ClientResources. You need to shut down the ClientResources upon shutting down your application. You can connect to different Redis servers but you must supply a RedisURI on connecting. Methods without having a RedisURI will fail with a IllegalStateException.
      Parameters:
      clientResources - the client resources, must not be null
      Returns:
      a new instance of RedisModulesClient
    • create

      public static RedisModulesClient create(io.lettuce.core.resource.ClientResources clientResources, String uri)
      Create a new client that connects to the supplied uri with shared ClientResources.You need to shut down the ClientResources upon shutting down your application. You can connect to different Redis servers but you must supply a RedisURI on connecting.
      Parameters:
      clientResources - the client resources, must not be null
      uri - the Redis URI, must not be null
      Returns:
      a new instance of RedisModulesClient
    • create

      public static RedisModulesClient create(io.lettuce.core.resource.ClientResources clientResources, io.lettuce.core.RedisURI redisURI)
      Create a new client that connects to the supplied uri with shared ClientResources. You need to shut down the ClientResources upon shutting down your application.You can connect to different Redis servers but you must supply a RedisURI on connecting.
      Parameters:
      clientResources - the client resources, must not be null
      redisURI - the Redis URI, must not be null
      Returns:
      a new instance of RedisModulesClient
    • builder

      public static RedisModulesClientBuilder builder()
    • uriBuilder

      public static RedisURIBuilder uriBuilder()
    • connect

      Open a new connection to a Redis server that treats keys and values as UTF-8 strings.
      Overrides:
      connect in class io.lettuce.core.RedisClient
      Returns:
      A new stateful Redis connection
    • connect

      public <K, V> StatefulRedisModulesConnection<K,V> connect(io.lettuce.core.codec.RedisCodec<K,V> codec)
      Open a new connection to a Redis server. Use the supplied codec to encode/decode keys and values.
      Overrides:
      connect in class io.lettuce.core.RedisClient
      Type Parameters:
      K - Key type
      V - Value type
      Parameters:
      codec - Use this codec to encode/decode keys and values, must not be null
      Returns:
      A new stateful Redis connection
    • connect

      public StatefulRedisModulesConnection<String,String> connect(io.lettuce.core.RedisURI redisURI)
      Open a new connection to a Redis server using the supplied RedisURI that treats keys and values as UTF-8 strings.
      Overrides:
      connect in class io.lettuce.core.RedisClient
      Parameters:
      redisURI - the Redis server to connect to, must not be null
      Returns:
      A new connection
    • connect

      public <K, V> StatefulRedisModulesConnection<K,V> connect(io.lettuce.core.codec.RedisCodec<K,V> codec, io.lettuce.core.RedisURI redisURI)
      Open a new connection to a Redis server using the supplied RedisURI and the supplied codec to encode/decode keys.
      Overrides:
      connect in class io.lettuce.core.RedisClient
      Type Parameters:
      K - Key type
      V - Value type
      Parameters:
      codec - Use this codec to encode/decode keys and values, must not be null
      redisURI - the Redis server to connect to, must not be null
      Returns:
      A new connection
    • newStatefulRedisConnection

      protected <K, V> StatefulRedisModulesConnectionImpl<K,V> newStatefulRedisConnection(io.lettuce.core.RedisChannelWriter channelWriter, io.lettuce.core.protocol.PushHandler pushHandler, io.lettuce.core.codec.RedisCodec<K,V> codec, Duration timeout)
      Create a new instance of StatefulRedisModulesConnectionImpl or a subclass.

      Subclasses of RedisModulesClient may override that method.

      Overrides:
      newStatefulRedisConnection in class io.lettuce.core.RedisClient
      Type Parameters:
      K - Key-Type
      V - Value Type
      Parameters:
      channelWriter - the channel writer
      codec - codec
      timeout - default timeout
      Returns:
      new instance of StatefulRedisModulesConnectionImpl