Use Connection pool with Jedis
JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", portno, 10000, "password");
See here: https://github.com/xetorthio/jedis/wiki/Getting-started
Check out Spring-data-redis.
When you add a JedisConnectionFactory
you get a connectionFactory which has connection pooling capability by default.
JedisConnectionFactory()
Constructs a new JedisConnectionFactory instance with default settings (default connection pooling, no shard information). See docs.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true" p:host-name="server" p:port="6379"/></beans>
For further information, see the documentation.