Spring Data Redis enableTransactionSupport连接不返回池

时间:2016-06-27 06:39:59

标签: spring-data-redis

当我将NAme Value employee id 2000001 employee name pankajkumar 设置为enableTransactionSupport时,连接不会返回到池中。即使true方法已经完成,连接也绑定到线程,这是一个大问题,如何解决呢?我使用spring-data-redis 2.7.2和jedis 2.8.1

@Transactional

连接没有释放到redis池,如果我没有使用<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="${redis.maxTotal}" /> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> <property name="testOnReturn" value="false" /> </bean> <bean id="jedisFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="${redis.host}" /> <property name="port" value="${redis.port}" /> <property name="usePool" value="true" /> <property name="poolConfig" ref="jedisPoolConfig" /> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="jedisFactory" /> <property name="enableTransactionSupport" value="true" /> <property name="defaultSerializer"> <bean class="com.wd.ics.util.CustomRedisSerializer" /> </property> </bean> ,则没关系。但它不支持Spring.how的enableTransactionSupport来解决它吗?

1 个答案:

答案 0 :(得分:1)

你可以像这样取消绑定绑定连接。

RedisConnectionUtils.unbindConnection(redisTemplate.getConnectionFactory());

如果你使用jedis。它将返回到池的连接。

if (pool != null) {
        if (!broken) {
            // reset the connection
            try {
                if (dbIndex > 0) {
                    jedis.select(0);
                }
                pool.returnResource(jedis);
                return;
            } catch (Exception ex) {
                DataAccessException dae = convertJedisAccessException(ex);
                if (broken) {
                    pool.returnBrokenResource(jedis);
                } else {
                    pool.returnResource(jedis);
                }
                throw dae;
            }
        } else {
            pool.returnBrokenResource(jedis);
            return;
        }
    }