spring-projects / spring-data-redis

Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-redis/
Apache License 2.0
1.75k stars 1.16k forks source link

Cannot connect to Redis Sentinel using database greater 0 through Jedis #2103

Closed steam0 closed 3 years ago

steam0 commented 3 years ago

Hello,

I have previously asked this question directly to the Jedis-team redis/jedis#2567 but I don't really understand what is happening here. There are a few questions that I need to get adressed.

1. Is it supposed to be possible to use Redis sentinels and a specific Redis database (db > 0)?

While trying to connect to Redis using Sentinel and having the database property set to any number greater than 0, the applicaiton crashes. (Spring Boot 2.5.1, Spring Data Redis 2.5.1, Jedis 3.6.0) It seems like the new Jedis(hap.getHost(), hap.getPort(), sentinelConnectionTimeout, sentinelSoTimeout) line inside JedisSentinelPool.java in Jedis 3.6.0 crashes because we are trying to set the database number in redis sentinel rather than in the redis master node. See more in the jedis bug posted above.

Example configuration:

       @Bean
    fun jedisConnectionFactory(): RedisConnectionFactory? {
        val sentinelConfig = RedisSentinelConfiguration()
            .master("<your sentinel master>")
            .sentinel("<your sentinel server>", 26379)

        // This is the config creating the error, comment this in/out to test
        sentinelConfig.database = 2

        return JedisConnectionFactory(sentinelConfig)
    }

2. If we are supposed to use Redis sentinels and a specific database (db > 0), then how do I configure that?

Since configuring the sentinelConfig with a database number breaks the application, where and when should I do it?

Thank you so much in advance.

Demo app is attached below that show the problem. demo-app.zip

mp911de commented 3 years ago

Thanks for the report. The bug is on our side. Since the introduction of JedisClientConfig, we erroneously set the database number for the configuration object that is used to specify the Sentinel-specific node configuration. The only workaround would be using Lettuce instead of Jedis since Lettuce doesn't have that bug on its code path to initialize the client.

steam0 commented 3 years ago

But is the bug on your side Spring Data Redis or is it a bug in the client lib Jedis? If it is on your side, I will just wait until a fix is ready (which I believe won't take months and months?)

mp911de commented 3 years ago

It's on our side. The next releases are scheduled for late July (https://calendar.spring.io/).