Spring RedisTemplate: after call keys of 8 calls hang

I am using Spring RedisTemplate (spring -data-redis 1.7.1) to communicate with Redis. I need to get and then delete the keys using regexp (ex: "context: user1: *"). I use the method "RedisTemplate.keys (...)" to get an array of keys

{ String key = String.format("%s:%s:%s", context, userId,"*"); Set<byte[]> keys = redisTemplate.getConnectionFactory().getConnection().keys(key.getBytes()); logger.debug(String.format("test log")); } 

But at 8-9, an iterative call to restTemplates.keys (...) stops the execution of my java service. The method call does not return from the framework. My service hangs up. It also happens every time. The workaround is just restarting the service.

+3
java spring redis
source share
1 answer

Assuming you are using Jedis with a pool, you are running into running out of base connection pooling.

Each call to redisTemplate.getConnectionFactory().getConnection() allocates a new connection from the connection pool. Do you call connection.close() ?. If not, the pool is depleted. Pools begin to block your request (in the hope that another thread will return a connection so that it can be used by the thread that is requesting a connection).

+3
source share

All Articles