Issue
I have seen follwing example.
final JedisPoolConfig poolConfig = buildPoolConfig();
JedisPool jedisPool = new JedisPool(poolConfig, "localhost");
private JedisPoolConfig buildPoolConfig() {
final JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(128);
poolConfig.setMaxIdle(128);
poolConfig.setMinIdle(16);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis());
poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis());
poolConfig.setNumTestsPerEvictionRun(3);
poolConfig.setBlockWhenExhausted(true);
return poolConfig;
}
try (Jedis jedis = jedisPool.getResource()) {
// do operations with jedis resource
}
It returns only redis.clients.jedis.Jedis client, but I am using "jedis-4.0.0.jar" and I want use redis.clients.jedis.UnifiedJedis client with pooling mechanism is there any way to use this.
Solution
Instead of JedisPoolConfig you need ConnectionPoolConfig.
Also, since Jedis 4.0 you can't just send host in the respective constructor. So use any other alternate.
WARNING: This constructor only accepts a uri string as url.
final ConnectionPoolConfig poolConfig = buildPoolConfig();
UnifiedJedis jedis = new JedisPooled(poolConfig, "localhost", 6379);
private ConnectionPoolConfig buildPoolConfig() {
final ConnectionPoolConfig poolConfig = new ConnectionPoolConfig();
// change poolConfig as you want
return poolConfig;
}
// do operations with (unified) jedis object
Answered By - sazzad Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.