title: Using Lettuce with RedisTemplate throws exceptions
body: <p>I am trying to figure out why Lettuce is giving me so many problems while I'm running my performance tests comparing it to Jedis.</p>
  
  <p>I'm using spring-data-redis 1.8.11.RELEASE and I create custom proxy beans for interfaces to access redis through RedisTemplate. Redis is running in AWS and I use the cluster config endpoint provided by AWS as the node with 3 master and 3 slaves. Nothing special happens during the performance test. I simply call a service that reads a value from redis using RedisTemplate.</p>
  
  <p>The test always passes with no exceptions when using JedisConnectionFactory, but when I switch to LettuceConnnectionFactory I cannot complete any of the tests because the channel initialization always times out. I increased the timeout to 30s and adjusted the shutdown timer as before I was getting thread interruption exceptions. However, even with 30s it still times out. I've tried with shared native connection and without and many different timeout values and they all result in the same problem. </p>
  
  <p>The code for the connection factory bean:</p>
  
  <pre><code>@Bean
  public RedisConnectionFactory lettuceConnectionFactory() {
      RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration(Arrays.asList(cacheProps.nodes));
      clusterConfig.setMaxRedirects(6);
      LettuceConnectionFactory factory = new LettuceConnectionFactory(clusterConfig);
      factory.setTimeout(30000);
      factory.setShutdownTimeout(20000);
      return factory;
  }
  </code></pre>
  
  <p>I tried tweaking the thread count for ClientResources, but I still continue to get timeout errors:</p>
  
  <pre><code>ClientResources res = DefaultClientResources.builder()
              .ioThreadPoolSize(10)
              .computationThreadPoolSize(10)
              .build();
  </code></pre>
  
  <p>The code to access Redis is simply going through RedisTemplate:</p>
  
  <pre><code>BoundHashOperations&lt;Object, Object, Object&gt; hashOps = redisTemplate.boundHashOps(request.getHashKey());
  String data = (String) hashOps.get(request.getSubKey());
  long timeout = request.getTtl();
  try {
      if (timeout != 0) {
          hashOps.expire(timeout, request.getTimeUnit());
      }
      return mapper.readValue(data, request.getType());
  } catch (Exception e) {
      logger.error("Exception for hash value read.", e);
  }
  </code></pre>
  
  <p>The root cause of the exceptions while testing:</p>
  
  <pre><code>Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /x.x.x.x:6379
  at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:216)
  at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
  at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:120)
  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:408)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:402)
  at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
  at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
  </code></pre>
  
  <p>What am I missing here? From everything I read, everyone seems to prefer Lettuce, but from my tests I can't see why.</p>