Class RedisProvider

java.lang.Object
com.ohalee.database.redis.RedisProvider
All Implemented Interfaces:
com.ohalee.database.api.DatabaseProvider<io.lettuce.core.api.StatefulRedisConnection<String,String>>

public class RedisProvider extends Object implements com.ohalee.database.api.DatabaseProvider<io.lettuce.core.api.StatefulRedisConnection<String,String>>
Implementation of DatabaseProvider for Redis using the Lettuce client.

This provider manages a RedisClient and a connection pool. It also supports a separate Pub/Sub connection.

  • Constructor Details

    • RedisProvider

      public RedisProvider(RedisCredentials credentials)
      Creates a new RedisProvider with the given credentials.
      Parameters:
      credentials - The Redis credentials.
  • Method Details

    • withRedisURI

      public io.lettuce.core.RedisURI withRedisURI(io.lettuce.core.RedisURI redisURI)
      Sets a custom RedisURI to be used by the RedisClient. Must be called before connect().
      Parameters:
      redisURI - The RedisURI to use.
      Returns:
      The RedisURI set.
    • withClientResources

      public RedisProvider withClientResources(io.lettuce.core.resource.ClientResources clientResources)
      Sets the ClientResources to be used by the RedisClient. Must be called before connect().
      Parameters:
      clientResources - The client resources to use.
    • withClientOptions

      public RedisProvider withClientOptions(io.lettuce.core.ClientOptions clientOptions)
      Sets the ClientOptions to be used by the RedisClient. Must be called before connect().
      Parameters:
      clientOptions - The client options to use.
    • connect

      public void connect()
      Specified by:
      connect in interface com.ohalee.database.api.DatabaseProvider<io.lettuce.core.api.StatefulRedisConnection<String,String>>
    • disconnect

      public void disconnect()
      Specified by:
      disconnect in interface com.ohalee.database.api.DatabaseProvider<io.lettuce.core.api.StatefulRedisConnection<String,String>>
    • getConnection

      public io.lettuce.core.api.StatefulRedisConnection<String,String> getConnection()
      Specified by:
      getConnection in interface com.ohalee.database.api.DatabaseProvider<io.lettuce.core.api.StatefulRedisConnection<String,String>>
    • pubSubConnection

      public io.lettuce.core.pubsub.StatefulRedisPubSubConnection<String,String> pubSubConnection()
      Gets the dedicated Pub/Sub connection.
      Returns:
      The Pub/Sub connection.