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 usingSocket s = new Socket("my_cache.redis.cache.windows.net", 6380)
is successfull.
Thanks,