Return a connection to a connection pool in JedisCluster

74 Views Asked by At

In my code I need to get a connection from JedisCluster instance for various reasons. Other operations are using jedisCluster instance to send commands:

val poolConfig = GenericObjectPoolConfig<Connection>().apply {
   maxTotal = 128
   maxIdle = 32
   minIdle = 8
   setMaxWait(Duration.ofMillis(1000))
   blockWhenExhausted = true
}
...
val jedisCluster = JedisCluster(HostAndPort(host, port), jedisConfigBuilder.build(), maxAttempts, poolConfig)
...
val connection = jedisCluster.getConnectionFromSlot(slotNumber)
// run operations
// Now I want to release that connection, but not close it!
...

However the connection is not getting back to the pool and unavailable for picking again. Closing this connection is not a good option, because I still want to reuse it from other places.
I specifically want to return it to the pool.
Any Ideas how to do it in a elegant manner?
I provided kotlin code, but any example in Java is also appreciated!

0

There are 0 best solutions below