title: Spring-data-redis connection pool not working as I expect
body: <p>This is my first application using spring-data-redis and I think I get the concepts pretty well (I've used JdbcTemplate many times with RDBMS-es in the past). Here's what's happening...</p>
  
  <p>The problem I'm running into is that every time I do a get(key) operation (using a ValueOperations object) a connection is opened and closed which causes an approximately 1/10th second delay (<em>this is server code, so 1/10th second is substantial</em>).  Here's the spring XML configuration:</p>
  
  <pre><code>&lt;!-- Redis DAO stuff --&gt;
  &lt;bean
      id="jedisPoolConfig"
      class="redis.clients.jedis.JedisPoolConfig"
      p:testOnBorrow="true"
      p:testOnReturn="true"
      p:timeBetweenEvictionRunsMillis="60000"
      p:minIdle="2"
      p:maxTotal="30"
      p:maxIdle="10"
    /&gt;
  
  &lt;bean id="jedisConnectionFactory"
      class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
      p:host-name="${redis.url}"
      p:port="${redis.port}"
      p:database="0"
      p:use-pool="true"
      p:pool-config-ref="jedisPoolConfig"
  /&gt;
  
  &lt;bean id="stringRedisSerializer"
      class="org.springframework.data.redis.serializer.StringRedisSerializer"
  /&gt;
  
  &lt;bean id="redisTemplate"
      class="org.springframework.data.redis.core.RedisTemplate" 
      p:connection-factory-ref="jedisConnectionFactory"
      p:defaultSerializer-ref="stringRedisSerializer"
  /&gt;
  </code></pre>
  
  <p>and here is the relevant Java code:</p>
  
  <pre><code>@Autowired
  private RedisTemplate&lt;String, String&gt; template;
  private ValueOperations&lt;String, String&gt; valOps;
  
  @PostConstruct
  public void init() {
      logger.debug("111111111111111111111111aaaaaaaaaaaaaaaaaaaaaaa");
      valOps = template.opsForValue();
  }
  
  public String getTestVal() {
      logger.debug("getTestVal() function called++++++++++++++++++++");
      Object testVal2 = valOps.get("akey");
      testVal2 = valOps.get("akey");
      testVal2 = valOps.get("akey");
      testVal2 = valOps.get("akey");
      testVal2 = valOps.get("akey");
      testVal2 = valOps.get("akey");
  
      logger.debug("TestVal2 returned from REdis: " + testVal2);
  
      return null;
  }
  </code></pre>
  
  <p>So the value for the same key is being retrieved six times.  The log output that I see is as follows:</p>
  
  <pre><code>13:46:37.011 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - getTestVal() function called++++++++++++++++++++
  13:46:37.014 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:37.344 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:37.416 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:37.543 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:37.616 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:37.742 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:37.812 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:37.940 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:38.003 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:38.128 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:38.201 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
  13:46:38.337 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
  13:46:38.414 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO -  TestVal2 returned from REdis: yo mama
  </code></pre>
  
  <p>I thought I had followed the docs on how to set up a connection pool, but when dealing with a performance-oriented platform such as Redis, I would <em>not</em> expect this delay I'm seeing.</p>
  
  <p>Thank you in advance for any assistance or hints.</p>