我需要使用带有密码的Azure Redis群集和SSL,以及流水线支持。
到目前为止,我一直在使用Jedis,但它缺乏对cluster + ssl + password + pipelining combo的支持。
我尝试了生菜(https://github.com/mp911de/lettuce/releases/tag/4.1.2.Final),目前遇到了我无法自行解决的连接问题。
连接到Azure Redis群集(2 * P4)无需SSL即可使用,但不能使用。 此外,我可以使用SSL连接到单个节点,但不支持群集。 问题是当组合cluster + ssl时,auth调用超时(该命令通过线路发送但超时)。
没有SSL工作代码的群集如下所示:
RedisURI redisURI = RedisURI.Builder.redis(host, 6379)
.withPassword(password)
.build();
RedisClusterClient client = RedisClusterClient.create(redisURI);
RedisAdvancedClusterCommands<String, String> connection = client.connect().sync();
connection.set("a", "1");
System.out.println(connection.get("a"));
输出为1
启用SSL:
RedisURI redisURI = RedisURI.Builder.redis(host, 6380)
.withPassword(password)
.withSsl(true)
.build();
RedisClusterClient client = RedisClusterClient.create(redisURI);
RedisAdvancedClusterCommands<String, String> connection = client.connect().sync();
connection.set("a", "1");
System.out.println(connection.get("a"));
它在1分钟内挂起,log4j日志如下所示:
2016-05-26 14:25:17,110 | TRACE | lettuce-nioEventLoop-3-1 | CommandEncoder | [/{CLIENT} -> {HOST}/{IP}:6380] Sent: *2
$4
AUTH
$44
{PASSWORD}
2016-05-26 14:26:17,134 | WARN | main | ClusterTopologyRefresh | Cannot connect to RedisURI [host='***', port=6380]
com.lambdaworks.redis.RedisCommandTimeoutException: Command timed out
at com.lambdaworks.redis.LettuceFutures.await(LettuceFutures.java:95)
at com.lambdaworks.redis.LettuceFutures.awaitOrCancel(LettuceFutures.java:74)
at com.lambdaworks.redis.AbstractRedisAsyncCommands.auth(AbstractRedisAsyncCommands.java:64)
at com.lambdaworks.redis.cluster.RedisClusterClient.connectToNode(RedisClusterClient.java:342)
at com.lambdaworks.redis.cluster.RedisClusterClient.connectToNode(RedisClusterClient.java:301)
at com.lambdaworks.redis.cluster.ClusterTopologyRefresh.getConnections(ClusterTopologyRefresh.java:240)
at com.lambdaworks.redis.cluster.ClusterTopologyRefresh.loadViews(ClusterTopologyRefresh.java:132)
at com.lambdaworks.redis.cluster.RedisClusterClient.loadPartitions(RedisClusterClient.java:468)
at com.lambdaworks.redis.cluster.RedisClusterClient.initializePartitions(RedisClusterClient.java:445)
at com.lambdaworks.redis.cluster.RedisClusterClient.connectClusterImpl(RedisClusterClient.java:359)
at com.lambdaworks.redis.cluster.RedisClusterClient.connect(RedisClusterClient.java:244)
at com.lambdaworks.redis.cluster.RedisClusterClient.connect(RedisClusterClient.java:231)
at com.ubikod.ermin.reach.tools.Test.main(Test.java:20)
Exception in thread "main" com.lambdaworks.redis.RedisException: Cannot retrieve initial cluster partitions from initial URIs [RedisURI [host='***', port=6380]]
at com.lambdaworks.redis.cluster.RedisClusterClient.loadPartitions(RedisClusterClient.java:471)
at com.lambdaworks.redis.cluster.RedisClusterClient.initializePartitions(RedisClusterClient.java:445)
at com.lambdaworks.redis.cluster.RedisClusterClient.connectClusterImpl(RedisClusterClient.java:359)
at com.lambdaworks.redis.cluster.RedisClusterClient.connect(RedisClusterClient.java:244)
at com.lambdaworks.redis.cluster.RedisClusterClient.connect(RedisClusterClient.java:231)
at com.ubikod.ermin.reach.tools.Test.main(Test.java:20)
保持SSL并禁用群集:
RedisURI redisURI = RedisURI.Builder.redis(host, 6380)
.withPassword(password)
.withSsl(true)
.build();
RedisClient client = RedisClient.create(redisURI);
RedisCommands<String, String> connection = client.connect().sync();
connection.set("a", "1");
System.out.println(connection.get("a"));
因此,这不仅仅是SSL问题,而是SSL +群集组合问题。
我试图使用withStartTls
,禁用对等验证,提高超时,没有运气的任何组合。
是否存在库错误或Azure Redis错误?
答案 0 :(得分:2)
我检查了lettuce
的wiki page,我注意到问题不是由库错误或Azure Redis错误造成的,不幸的是,只有lettuce
不支持Redis使用SSL的群集,请参阅维基页面的Connecting to Redis using String RedisURI
小节中的以下内容。
仅在常规Redis连接上支持SSL。不支持使用Redis Sentinel或Redis群集的主分辨率,因为两种策略都为本机端口提供Redis地址。 Redis Sentinel和Redis Cluster无法提供SSL端口。