title: RedisTemplate with Lettuce seems to get new connection on each request
body: <p>For a spring boot app I am using RedisTemplate injected into a service bean to do simple gets/sets. This is for AWS Elasticache cluster enabled. I started the app and sent a few requests thru and the performance is slow and the Elasticache metrics show new connections equivalent to the number of requests.  By slow I am seeing times of roughly 100ms for each call.  The long latency and metrics for new connections indicates the native connection in the LettuceConnection is not retained.  I am only using spring-data to manage getting the connection setup.  Specifically, I don't want to connect in a @Config class and have the app fail on startup if there is an issue connecting. It's a critical app that needs to start even if the cache is not available at that time.  And I don't want to write the code to synchronize getting the single native connection during multi-threaded access.  Any ideas why the native connection would not be saved?  Here's my config: </p>
  
  <pre><code>    private ClusterClientOptions clusterClientOptions() {
      //@formatter:off
      return ClusterClientOptions.builder()
              .socketOptions(SocketOptions
                      .builder()
                      .connectTimeout(Duration.ofMillis(properties.getConnectionTimeoutMs()))
                      .build())
              .requestQueueSize(properties.getRequestQueueSize())
              .topologyRefreshOptions(ClusterTopologyRefreshOptions
                      .builder()
                      .enablePeriodicRefresh(properties.isPeriodicRefresh())
                      .build())
              .build();
      //@formatter:on
  }
  
  private LettuceClientConfiguration lettuceClientConfiguration() {
      //@formatter:off
      return LettuceClientConfiguration
          .builder()
          .clientOptions(clusterClientOptions())
          .commandTimeout(Duration.ofMillis(properties.getCommandTimeoutMs()))
          .useSsl()
          .build();
      //@formatter:on
  }
  
  private LettuceConnectionFactory serviceContextLettuceConnectionFactory() {
  
      RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration();
      clusterConfig.clusterNode(properties.getCacheEndpoint(), properties.getCachePort());
      clusterConfig.setPassword(RedisPassword.of(properties.getCachePassword()));
  
      LettuceConnectionFactory lettuceConnectionFactory =
              new LettuceConnectionFactory(clusterConfig, lettuceClientConfiguration());
      lettuceConnectionFactory.setShareNativeConnection(true);
      lettuceConnectionFactory.afterPropertiesSet();
  
      return lettuceConnectionFactory;
  }
  
  private RedisTemplate&lt;String, String&gt; redisTemplate() {
      RedisTemplate&lt;String, String&gt; template = new RedisTemplate&lt;&gt;();
      template.setConnectionFactory(serviceContextLettuceConnectionFactory());
      template.afterPropertiesSet();
      return template;
  }
  </code></pre>
  
  <p>The template gets set into a singleton service class which calls template.opsForValue().get(key), etc.  It works but it's slow and always creating new connections.</p>