title: Spring Data Redis issue with connection pooling
body: <p>I am using Spring Data Redis and need have an issue with <code>JedisPoolConfig</code>. I have configured a <code>RedisTemplate</code> as follows:</p>
  
  <pre><code>@Bean
  JedisPoolConfig jedisPoolConfig() {
  
      JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
      return jedisPoolConfig;
  }
  
  @Bean
  public RedisConnectionFactory redisConnectionFactory() {
  
      JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig());
      jedisConnectionFactory.setHostName(redisSettings.getServer().getHost());
      jedisConnectionFactory.setPort(redisSettings.getServer().getPort());
      return jedisConnectionFactory;
  }
  
  @Bean
  public RedisTemplate&lt;String, Integer&gt; redisTemplate(RedisConnectionFactory redisConnectionFactory) {
  
      RedisTemplate&lt;String, Integer&gt; redisTemplate = new RedisTemplate&lt;String, Integer&gt;();
      redisTemplate.setConnectionFactory(redisConnectionFactory);
      redisTemplate.setKeySerializer(new StringRedisSerializer());
      redisTemplate.setEnableTransactionSupport(true);
      return redisTemplate;
  }
  </code></pre>
  
  <p>I have a service that is marked as <code>@Transactional</code>, which in turns calls a <code>@Repository</code> that increments a number of keys in Redis:</p>
  
  <pre><code>@Service
  @Transactional
  public class MyService {
  
      @Autowired
      MyRepository myRepository;
  
      public void recordStats() {
  
          myRepository.recordStats();
      }
  
  }
  
  
  @Repository
  public class MyRepository {
  
      @Resource(name="redisTemplate")
      ValueOperations&lt;String, Integer&gt; valueOperations;
  
      public void recordStats() {
  
          valueOperations.increment("KEY01", 1);
          valueOperations.increment("KEY02", 1);
          valueOperations.increment("KEY03", 1);
          valueOperations.increment("KEY04", 1);
          valueOperations.increment("KEY05", 1);
          valueOperations.increment("KEY06", 1);
          valueOperations.increment("KEY07", 1);
          valueOperations.increment("KEY08", 1);
          valueOperations.increment("KEY09", 1);
          valueOperations.increment("KEY10", 1);
          valueOperations.increment("KEY11", 1);
      }
  }
  </code></pre>
  
  <p>When I call <code>myService.recordStats()</code> and step through the code in debug, it hangs upon trying to increment KEY11, and ultimately fails with <code>redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool</code>. If I amend the <code>JedisPoolConfig</code> to increase the MaxTotal as follows:</p>
  
  <pre><code>@Bean
  JedisPoolConfig jedisPoolConfig() {
  
      JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
      jedisPoolConfig.setMaxTotal(128);
      return jedisPoolConfig;
  }
  </code></pre>
  
  <p>Then the problem goes away, and I can increment all 11 keys in a transaction. It seems to be the case that every <code>valueOperations.increment</code> call is taking another connection from the pool. Is this correct, or do I have a configuration problem somewhere?</p>