Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring RedisTemplate: after 8 calls method keys hangs up

Tags:

java

spring

redis

I use Spring RedisTemplate (spring-data-redis 1.7.1) for communication with Redis. I need to get and then delete keys by regexp (ex: "context:user1:*"). I use method "RedisTemplate.keys(...)" for getting 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 on 8-9 iteration call restTemplates.keys(...) stops execution of the my java service. The call of method is not returned from framework. My service is hangs up. Also it is happening everytime. Workaround is only restart my service.

like image 761
Dmitry Igumnov Avatar asked Apr 14 '16 12:04

Dmitry Igumnov


1 Answers

Assuming you're using Jedis with pooling, you run into an exhaustion of the underlying connection pool.

Each call to redisTemplate.getConnectionFactory().getConnection() allocates a new connection from the connection pool. Do you call connection.close()?. If not, the pool gets exhausted. The pools starts to block your request (hoping another thread will return a connection so it can be used by the thread which requests a connection).

like image 190
mp911de Avatar answered Sep 23 '22 17:09

mp911de