We are using Redis v3.2.100 windows version for caching in a Spring Framework project. Redis related dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.0</version>
</dependency>
And config:
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" p:max-total="400" p:maxIdle="350" p:maxWaitMillis="1000"
p:test-on-borrow="true" p:test-on-return="true" p:testOnCreate="true" />
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="127.0.0.1" p:port="6379" p:use-pool="true" p:password="11223344">
<constructor-arg ref="jedisPoolConfig"/>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory" p:enable-transaction-support="true"/>
And the usage sample in Kotlin:
@Resource(name = "redisTemplate")
private val redisLongKeyStrValueHashOps: HashOperations<String, Long, String>? = null
...
{
...
redisLongKeyStrValueHashOps!!.get("RepoName", 111L).toString()
...
}
But there is a problem, sometimes Spring Application cannot work with Redis and connection of server with Redis lost. If we check the status of Redis at that moment, the connection count is around 1600 and, if we restart Spring Application, connection count return to zero! and everything becomes fine!