-
Notifications
You must be signed in to change notification settings - Fork 53
Redis Sentinel URIs are not parsed correctly #175
Description
Attempting to use riot with a sentinel URI such as redis-sentinel://host1:26379,host2:26380/?sentinelMasterId=foo fails with the following error:
java.lang.IllegalStateException: Cannot build a RedisURI. One of the following must be provided Host, Socket or Sentinel
RedisURI.create supports sentinel URIs, but the sentinel info is lost when the URI gets copied through lettucemod's RedisURIBuilder. It uses RedisURI.builder to initialize a builder from the URI, but the method only copies a subset of fields from the URI, and it has the effect of stripping the sentinel info.
This test case demonstrates the problem:
@Test
void redisArgsSentinelURI() {
RedisArgs args = new RedisArgs();
RedisURI uri = RedisURI.create("redis-sentinel://host1:26379,host2:26380/?sentinelMasterId=foo");
args.setUri(uri);
RedisContext context = RedisContext.of(args);
Assertions.assertEquals("foo", context.getUri().getSentinelMasterId());
List<RedisURI> sentinels = context.getUri().getSentinels();
Assertions.assertEquals(2, sentinels.size());
}RedisArgsTests > redisArgsSentinelURI() FAILED
java.lang.IllegalStateException: Cannot build a RedisURI. One of the following must be provided Host, Socket or Sentinel
at io.lettuce.core.RedisURI$Builder.build(RedisURI.java:1857)
at com.redis.lettucemod.RedisURIBuilder.build(RedisURIBuilder.java:52)
at com.redis.riot.RedisContext.of(RedisContext.java:102)
at com.redis.riot.RedisContext.of(RedisContext.java:108)
at com.redis.riot.RedisArgsTests.redisArgsSentinelURI(RedisArgsTests.java:30)
✘ Test com.redis.riot.RedisArgsTests [Tests: 4/3/1/0] [Time: 0.084 s]
The problem is fixed in lettucemod v4.3.0, as it now explicitly copies the sentinel info after calling RedisURI.builder.
Unfortunately, v4.3.0 contains a significant refactor and is a breaking change. It's not too bad to fix-up the direct references in this repo, but lettucemod is also used transitively by spring-batch-redis-infrastructure/spring-batch-redis-core, and those packages would have to be updated too. (and their source repos seem to have disappeared from github?) My workaround solution is to copy RedisURIBuilder into this repo, and apply the same fix to it that was made in v4.3.0.