Search code examples
javaredisspring-data-redis

Could redisTemplate.executePipelined cause SocketTimeOut


This is my code :

redisTemplate.executePipelined(new SessionCallback<Object>() {
    @Override
    public Object execute(RedisOperations redisOperations) throws DataAccessException {
        redisTemplate.opsForSet().add(e, businessCode);
        return null;
    }
});

inner code “redisTemplate.opsForSet().add(e, businessCode);” is using the one connection

Thanks for answer

supplement stack error info:

org.springframework.data.redis.RedisConnectionFailureException: java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
    at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
    at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37)
    at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:241)
    at org.springframework.data.redis.connection.jedis.JedisConnection.zRange(JedisConnection.java:2348)
    at org.springframework.data.redis.connection.DefaultStringRedisConnection.zRange(DefaultStringRedisConnection.java:1058)
    at org.springframework.data.redis.core.DefaultZSetOperations$5.doInRedis(DefaultZSetOperations.java:101)
    at org.springframework.data.redis.core.DefaultZSetOperations$5.doInRedis(DefaultZSetOperations.java:98)
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207)
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
    at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
    at org.springframework.data.redis.core.DefaultZSetOperations.range(DefaultZSetOperations.java:98)
    at com.*.mshop.reach.service.impl.ReachServiceImpl.query(ReachServiceImpl.java:178)
    at com.*.mshop.reach.service.impl.ReachServiceImpl$$FastClassBySpringCGLIB$$633d23e1.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:667)
    at com.*.mshop.reach.service.impl.ReachServiceImpl$$EnhancerBySpringCGLIB$$486aa953.query(<generated>)
    at com.*.mshop.facade.controller.ReachControllerImpl.query$original$1525E0bP(ReachControllerImpl.java:174)
    at com.*.mshop.facade.controller.ReachControllerImpl.query$original$1525E0bP$accessor$dcQnJrPQ(ReachControllerImpl.java)
    at com.*.mshop.facade.controller.ReachControllerImpl$auxiliary$jZ0njKo2.call(Unknown Source)
    at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
    at com.*.mshop.facade.controller.ReachControllerImpl.query(ReachControllerImpl.java)
    at com.*.mshop.facade.controller.ReachControllerImpl.queryCommodity$original$1525E0bP(ReachControllerImpl.java:203)
    at com.*.mshop.facade.controller.ReachControllerImpl.queryCommodity$original$1525E0bP$accessor$dcQnJrPQ(ReachControllerImpl.java)
    at com.*.mshop.facade.controller.ReachControllerImpl$auxiliary$NkOmWqfY.call(Unknown Source)
    at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
    at com.*.mshop.facade.controller.ReachControllerImpl.queryCommodity(ReachControllerImpl.java)
    at com.*.mshop.facade.controller.ReachControllerImpl$$FastClassBySpringCGLIB$$c8f1c1b6.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

before this exception called executePipelined , about 1 minutes , cound not get redis connection .

redis connection pool config :

spring.redis.pool.max-active = 2000
spring.redis.pool.max-wait = 5000
spring.redis.pool.max-idle = 200
spring.redis.pool.min-idle = 10
spring.redis.timeout = 0

Solution

  • Redis Pipeline have different implement for Jedis and Lettuce.

    In Jedis, pipeline will block 1 connection and send all pipeline commands together with same connection(bio)

    In Lettuce, pipeline use Netty nio as network connection tool. So during the pipeline execute in client side, it will not block the connection(generally lettuce will use single connection). And when pipeline execute(send to Redis), it will select 1 connection from Netty.

    And both libraries are using same connection for pipeline commands as they will send all commands together in a single network request.