Redis Sentinel Support
Redis Client Builder provides support for Redis Sentinel configuration, allowing you to build Redis clients that connect through Redis Sentinel for high availability.
What is Redis Sentinel?
Redis Sentinel provides high availability for Redis. It monitors your Redis instances, notifies you about changes in their state, and automatically performs failover if a master is not working as expected.
Jedis Sentinel
Redis Client Builder supports building Jedis clients with Sentinel configuration:
Kotlin Example
val jedisSentinelPool = RedisClientBuilderFactory.jedisSentinel()
.masterName("mymaster")
.addSentinel("sentinel1", 26379)
.addSentinel("sentinel2", 26380)
.addSentinel("sentinel3", 26381)
.password("password")
.database(0)
.connectionTimeout(2000)
.socketTimeout(2000)
.clientName("myclient")
.maxTotal(100)
.maxIdle(10)
.build()
// Use the JedisSentinelPool
jedisSentinelPool.resource.use { jedis ->
jedis.set("key", "value")
val value = jedis.get("key")
println(value)
}
Generic Sentinel Builder
You can also use the generic sentinel builder method to create a builder for a specific Redis sentinel client type:
val jedisSentinelBuilder = RedisClientBuilderFactory.sentinelBuilder(JedisSentinelPool::class.java) as JedisSentinelClientBuilder
Configuration Options
Common Options
These options are available for all Redis Sentinel client builders:
masterName(String)
: Sets the name of the Redis master that the sentinels are monitoringaddSentinel(String, Int)
: Adds a Redis sentinel node to the configurationpassword(String)
: Sets the password for authentication with the Redis sentineldatabase(Int)
: Sets the Redis database indexconnectionTimeout(Int)
: Sets the connection timeout in millisecondssocketTimeout(Int)
: Sets the socket timeout in millisecondsssl(Boolean)
: Enables SSL/TLS for the connection
Jedis Sentinel Options
These options are specific to the Jedis Sentinel client builder:
clientName(String)
: Sets the client namemaxTotal(Int)
: Sets the maximum number of connections that can be allocated by the pool at a given timemaxIdle(Int)
: Sets the maximum number of idle connections that can be maintained by the pool without being closedminIdle(Int)
: Sets the minimum number of idle connections to maintain in the pooltestOnBorrow(Boolean)
: Sets whether connections should be validated before being borrowed from the pooltestOnReturn(Boolean)
: Sets whether connections should be validated before being returned to the pooltestWhileIdle(Boolean)
: Sets whether idle connections should be validated by the idle connection evictortimeBetweenEvictionRuns(Long)
: Sets the time between runs of the idle connection evictor thread in millisecondsblockWhenExhausted(Boolean)
: Sets whether clients should block when the pool is exhaustedjmxEnabled(Boolean)
: Sets whether JMX should be enabled for the pool