连接不断从Java客户端堆积在Redis中

时间:2014-05-15 18:34:23

标签: java spring connection-pooling spring-data jedis

我在我的机器上安装了Redis,我在Spring应用程序中使用Jedis客户端将一些数据写入Redis。出于某些原因,每次写入时,Redis的连接数都会不断堆积,直到我收到JedisConnectionFailureException。

My Spring Jedis Config文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<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">


<!-- Redis conection factory configurations -->
<bean id="redisConnectionFactory"   class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
                                    p:host-name="${redis.host}" 
                                    p:port="${redis.port}" 
                                    p:password="${redis.password}"
                                    p:use-pool="true" />

<!-- Redis String Serializer -->
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

<!-- JDK Serialization Redis Serializer -->
<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>

<!-- Configuring the Redis Template -->
<bean id="redisTemplate"  class="org.springframework.data.redis.core.RedisTemplate"
                            p:connection-factory-ref="redisConnectionFactory" 
                            p:keySerializer-ref="stringRedisSerializer"
                            p:valueSerializer-ref="jdkSerializationRedisSerializer" />

在我的整个应用中,这是我创建连接的唯一地方。

在我的spring-app中,我使用如下连接:

redisTemplate.opsForValue().set("key", "value");

1 个答案:

答案 0 :(得分:0)

问题在于错误的Spring Data Redis TX Sync算法 - 它有bugs

它已修复,自Spring Data Redis 1.3 GA

以来可用
相关问题