java.util.concurrent.ExecutionException: redis.clients.jedis.exceptions.JedisDataException: ERR max number of clients reached -
i trying connect redis database using jedis-client in web application after day application throwing exception below:
java.util.concurrent.executionexception: redis.clients.jedis.exceptions.jedisdataexception: err max number of clients reached
i tried figure out due redis not able handle connection or may have not close redis connection.
//code snippet connect redis jedis jedis = new jedis("localhost"); jedis.connect();
i have not closed connection thinking connection close redis-server idle. may cause.
you seem opening connection every time query redis server. after while many clients connected , server cannot accept new connections.
there several options:
disconnect idle clients server side
if want redis server disconnect idle clients, should redis configuration: # close connection after client idle n seconds (0 disable) timeout 0
see reference redis conf. have value set @ 0. changing , restarting redis server should solve issue.
close connection client side
just call
jedis.quit();
this tell both server , client close connection. if there no need maintain connection, it's more elegant.
use connection pool
if have several clients/threads in redis application should use connection pool in jedis client. should included in dependency.
it maintain/recreate connections when needed. query pool when need connection , give when done querying (exactly jdbc pool).
here basic example documentation.
Comments
Post a Comment