jedis
jedis copied to clipboard
JedisPooled ## Could not get a resource from the pool
Expected behavior
Java Jedis client work with thousands of reads and write on redis server.
Actual behavior
Jedis client gives Could not get a resource from the pool
error while performing huge write and read operations on redis client
Stack trace
Error : Could not get a resource from the pool
redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
at redis.clients.jedis.util.Pool.getResource(Pool.java:42) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:29) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:7) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.providers.PooledConnectionProvider.getConnection(PooledConnectionProvider.java:68) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.executors.DefaultCommandExecutor.executeCommand(DefaultCommandExecutor.java:23) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.UnifiedJedis.executeCommand(UnifiedJedis.java:183) ~[jedis-4.4.3.jar:?]
at redis.clients.jedis.UnifiedJedis.set(UnifiedJedis.java:651) ~[jedis-4.4.3.jar:?]
at com.ashok.redis.manager.RedisCacheStore.putCache(RedisCacheStore.java:155) ~[redis-manager-17.1.0.jar:?]
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(Unknown Source) ~[?:?]
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source) ~[?:?]
at org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:594) ~[commons-pool2-2.8.0.jar:2.8.0]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:437) ~[commons-pool2-2.8.0.jar:2.8.0]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:354) ~[commons-pool2-2.8.0.jar:2.8.0]
at redis.clients.jedis.util.Pool.getResource(Pool.java:38) ~[jedis-4.4.3.jar:?]
... 27 more
Steps to reproduce:
Please create a reproducible case of your problem. Make sure that case repeats consistently and it's not random
- Deploy Redis standalone deployment in Kubernetes cluster
- Deploy Java Application with Jedis client in the same Kubernetes cluster
- Perform reads and writes with JedisPooled class
Java Code Snippets Redis connection initialization
JedisPooled jedisPool = null;
private RedisCacheStore( ) {
initRedisConnection();
}
private void initRedisConnection() {
try {
jedisPool = new JedisPooled("redis", 6379, timeout, "default", "Ashok@Redis");
} catch(Exception e) {
e.printStackTrace()
}
}
Inserting data to the redis server
public boolean putCache(String storeName, String key, String value) throws Exception {
String data = jedis.get(storeName);
JsonObject json;
if (data == null) {
json = new JsonObject();
} else {
Gson gson = new Gson();
json = gson.fromJson(data, JsonObject.class);
}
synchronized (jo) {
jo.addProperty(key, value);
jedis.set(storeName,jo.toString());
return true;
}
}
Redis / Jedis Configuration
Jedis version:
4.4.3
Redis version:
redis:7.2.4-debian-11-r0
Java version:
11.0.20.1