0

I am doing poc(Redis + springboot + jpa) ,when I am setting Redis Property setEnableTransactionSupport(true ) then exception of Transaction does not support in clustermode , when I am setting setEnableTransactionSupport(false) during getting redisTemplate then exception of resource pool is coming.

@Note: This problem is happing when I setup Redis and spring boot are on different machine. I have 6 nodes , 3 are master and 3 are slaves.

But When I setup whole on single machine(spring + Redis ), then it's working fine.

below are my dependencies:

[<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>]

[<groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.9.0</version>
        <type>jar</type>]

I have tried what was suggested in below link: Jedis, Cannot get jedis connection: cannot get resource from pool below is my configuration for Redis Connection factory:

## Redis Properties(application.properties)
spring.redis.cluster.nodes=127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002

RedisClusterConfigProp.java

@Component
@ConfigurationProperties(value = "spring.redis.cluster")
public class RedisClusterConfigProp {
List<String> nodes;
/**
 * @return the nodes
 */
public List<String> getNodes() {
    return nodes;
}

/**
 * @param nodes
 * the nodes to set
 */
public void setNodes(List<String> nodes) {
    this.nodes = nodes;
}

}

RedisClusterConfigration.java

@Configuration
public class RedisClusterConfigration {

@Autowired
public RedisClusterConfigProp clusterConfigProp;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory jedisConnFac = new JedisConnectionFactory(
            new RedisClusterConfiguration(clusterConfigProp.getNodes()), new JedisPoolConfig());
    jedisConnFac.getPoolConfig().setMaxIdle(40);
    jedisConnFac.getPoolConfig().setMinIdle(20);
    return jedisConnFac;
}

@Bean
public RedisTemplate redisTemplate() {
    RedisTemplate template = new RedisTemplate();
    template.setConnectionFactory(redisConnectionFactory());
    template.setEnableTransactionSupport(false);
    return template;
}
Rmahajan
  • 1,311
  • 1
  • 14
  • 23
Sanjay
  • 89
  • 1
  • 13
  • Can you explain your problem in more details ? Any exception stack trace ? – Rmahajan Jan 13 '19 at 21:53
  • Exception is:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool | org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poolorg.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is org.springframework.data.redis.core.DefaultHashOperations.get(DefaultHashOperations.java:49) – Sanjay Jan 14 '19 at 08:07
  • { "timestamp": 1547453703786, "status": 500, "error": "Internal Server Error", "message": "com.telus.thps.exception.UserProfileException: com.telus.thps.exception.UserProfileException: org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool", "path": "/app/v1/getUserProfile" } – Sanjay Jan 14 '19 at 08:15
  • It may be a network issue, because if i run my springboot app on same server where redis cluster is deploy, its working fine. – Sanjay Jan 14 '19 at 08:18
  • one more point came, during the spring application context every thing is fine, but when I send REST request to spring boot application , in my repository class when spring try to use redisTemplete , then it goes to get connection from redisConnectionPool, then it is passing 127.0.0.1 as host name to socket.connect(new InetSocketAddress(host, port), connectionTimeout); so that's why no connection found in pool and java.net.ConnectException: Connection refused: connect exception come., because my Redis cluster is running on remote server. – Sanjay Jan 14 '19 at 14:28

1 Answers1

0

If connection to node succeed but creating a connection (for r/w from) from the pool fails ("Could not get a resource from the pool" etc.) that may be because current master is on different node (which is probably configured during installation).

If redis sentinel is used (not redis cluster) in this case, ip:port list (in config file) will be used to connect to sentinels, but current master's ip:port (not those in config file) will be different. these ip:port configuration is provided during installation, or propably can be configured later.

Murat
  • 370
  • 4
  • 3