Reputation: 95
I am new to Redis and currently using Java 8, Java EE 7 and AWS Elastic Cache on Redis. Using my java knowledge, all resources should be closed/returned to the pool once the task is over.
pool= new JedisPool(new JedisPoolConfig(),"myendpoint.aws.com",6379,Protocol.DEFAULT_TIMEOUT);
try(Jedis jedis=pool.getResource();)
{
ListTask gt=new ListTask();
JsonArray listofTask=gt.getTutorials();
Map<String,String> attributes = new HashMap<>();
attributes.put("ListofTask",listofTask.toString());
jedis.hmset(key, attributes);
}
catch (Exception ex) {
Logger.getLogger(RedisOperation.class.getName()).log(Level.SEVERE,"setRedisListofTaskJSON", ex);
}
pool.close();
On clicking info, i get Connected clients as 149. This is just one box testing the application multiple times. And each time the connected_clients are increasing and memory is increasing.
Clients connected_clients:149 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0
Question : 1 How to close/house keep connections? 2 How to set an age/ttl on key?
Using JDK8, Java EE7 and Redis 2.8(using Jedis to connect).
Upvotes: 0
Views: 8327
Reputation: 622
Answer for your question 2 is using expire or expireat and ttl methods from Jedis class
Upvotes: 0
Reputation: 95
Since I used try-resources, there is no need to close jedis pool resource. At the end of the application, destory the pool by calling destroy method.
try(Jedis jedis=pool.getResource();)
{
jedis.hmset(key, attributes);
}catch (Exception ex) {
}
pool.destroy();
Original documentation https://github.com/xetorthio/jedis/wiki/Getting-started.
Upvotes: 1