Azure Redis Cache - keep getting: readAddress(..) failed: Connection reset by peer
I can connect using the redis cli, but not through Spring Boot Webflux, I keep getting readAddress(..) failed: Connection reset by peer
So, i figured this was a spring issue, using lettuce.
Here is my code:
@Bean
@Primary
fun reactiveRedisConnectionFactory(): ReactiveRedisConnectionFactory {
// Configure Redis standalone configuration
val config = RedisStandaloneConfiguration()
config.hostName = redisHostName
config.port = redisPort
config.setPassword(redisPassword) // Use the token as password
// Create socket options
val socketOptions = SocketOptions.builder()
.keepAlive(true)
.build()
// Create client options
val clientOptions = ClientOptions.builder()
.socketOptions(socketOptions)
.build()
// Create Lettuce client configuration with authentication details
val clientConfig = LettucePoolingClientConfiguration.builder()
.commandTimeout(Duration.ofSeconds(60))
.clientResources(DefaultClientResources.create())
.clientOptions(clientOptions)
.poolConfig(buildLettucePoolConfig())
.useSsl()
.build()
// Create Lettuce connection factory
return LettuceConnectionFactory(config, clientConfig).apply {
afterPropertiesSet()
}
}
protected fun buildLettucePoolConfig(): GenericObjectPoolConfig<Any> {
val poolConfig = GenericObjectPoolConfig<Any>()
poolConfig.maxTotal = 100
poolConfig.maxIdle = 50
poolConfig.minIdle = 50
poolConfig.setMaxWait(Duration.ofMillis(60000))
poolConfig.timeBetweenEvictionRuns = Duration.ofMillis(60000)
poolConfig.minEvictableIdleDuration = Duration.ofMillis(60000)
return poolConfig
}
}
spring.data.redis.host=hostname.redis.cache.windows.net
spring.data.redis.password=access-key
spring.data.redis.port=6380
And the error chain I keep getting, after about 10 seconds:
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to hostname.redis.cache.windows.net/:6380 Caused by: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer
Would be grateful for nay help and support
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior.
Expected behavior A clear and concise description of what you expected to happen.
Sample
A link to a GitHub repository with a minimal, reproducible sample.
Reports that include a sample will take priority over reports that do not. At times, we may require a sample, so it is good to try and include a sample up front.