1

My Spring boot app hosted in AKS Azure, while hitting the redis cache in Azure, getting Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to my_cache.redis.cache.windows.net/<unresolved>:6380

relevant configurations in yml:

spring:
  cache:
    type: redis
  redis:
    host: my_cache.redis.cache.windows.net
    ssl: true
    port: 6380
    password: ${REDIS_PRIMARY_ACCESS_KEY}

relevant codes

@Configuration
public class RedisConfig {

  private RedisProperties redisProperties;
  
  @Autowired
  public RedisConfig(RedisProperties redisProperties) {
    super();
    this.redisProperties = redisProperties;
  }

  @Bean
  @Primary
  public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory(RedisConfiguration defaultRedisConfig) {
      LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().commandTimeout(Duration.ofMillis(10000))
              .useSsl().build();
      return new LettuceConnectionFactory(defaultRedisConfig, clientConfig);
  }

  @Bean
  public RedisConfiguration defaultRedisConfig() {
      RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
      config.setHostName(redisProperties.getHost());
      config.setPassword(RedisPassword.of(redisProperties.getPassword()));
      config.setPort(redisProperties.getPort());
      return config;
  }

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {

  private String host;
  private String password;
  private int port;
  
  public String getHost() {
    return host;
  }
  public void setHost(String host) {
    this.host = host;
  }
  public String getPassword() {
    return password;
  }
  public void setPassword(String password) {
    this.password = password;
  }
  public int getPort() {
    return port;
  }
  public void setPort(int port) {
    this.port = port;
  }
  
}

@Service
@CacheConfig(cacheNames = {"TestPolicy"})
public class RedisServiceImpl implements RedisService {

  private Logger log = LoggerFactory.getLogger(RedisServiceImpl.class);
  
  @Override
  @Cacheable(key = "#policyNo")
  public PolicyTest getPolicyByNo(String policyNo) {
    log.info("RedisServiceImpl::getPolicyByNo() fetching TestPolicy from service ...");
    return new PolicyTest("123", "1001", "200578");
  }

}

And yes, I've referred similar threads like Unable to connect to Redis;nested exception is io.lettuce.core.RedisConnectionException using RedisTempalte without any luck.

  • is something wrong with the configuration?
  • Could it be some security issue ? pinging the redis host from java using InetAddress.getByName("my_cache.redis.cache.windows.net").isReachable(5000); and using Socket s = new Socket("my_cache.redis.cache.windows.net", 6380) is successfull.

Thanks,

user957183
  • 417
  • 3
  • 10
  • 20
  • Is your application running on a docker container? Both tests that you've performed where done where? Do you have the same results running a ping/telnet command on the host machine? – pringi Apr 27 '22 at 08:34
  • @pringi spring boot app runs in AKS cluster in Azure, and redis also runs in azure. The ping/telnet are performed from the spring boot app itself, which are working. – user957183 Apr 28 '22 at 06:21
  • 1
    one other thing is the unresolved in the exception stacktrace, I've no clue what is that – user957183 Apr 28 '22 at 06:22

0 Answers0