I'm not sure where I'm gonig wrong.
I can connect with redis cli, but not with Spring Boot Webflux.
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
The error I get is:
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
Not sure where I'm gonig wrong. Any ideas?
You are using the SSL port (6380). I think you need to use spring.data.redis.ssl.enabled
config property as well.