带有 Lettuce 的 Redis Spring 数据:com.lambdaworks.redis.RedisCommandExecutionException:MOVED 错误
Redis Spring data with Lettuce: com.lambdaworks.redis.RedisCommandExecutionException: MOVED error
我在集群模式下使用 AWS ElastiCache (Redis)。我有两个连接到 ElastiCache 的实现。其中一种实现方式是直接使用本机 Lettuce 驱动程序,其他使用 Spring 数据并将 Lettuce 作为底层驱动程序。 AWS ElastiCache 具有集群配置端点。我想使用此端点连接到 ElastiCache。我能够使用具有本机 Lettuce 驱动程序实现的集群端点成功连接到 ElastiCache,但是在使用 spring 数据和集群端点
时出现以下错误
Spring 数据:1.8.9-RELEASE(不能选择更高版本的 Spring)
生菜:4.5.0-最终版
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
lettuceConnectionFactory.setHostName(<cluster_endpoint>);
lettuceConnectionFactory.setPort();
lettuceConnectionFactory.setUseSsl(Boolean.valueOf(useSsl));
//lettuceConnectionFactory.setPassword(password);
return lettuceConnectionFactory;
}
错误:
Caused by: org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: MOVED 12894 cache---.usw2.cache.amazonaws.com:6379
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:50)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:48)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
它在以下两种情况下工作正常 -
1) 我使用集群节点端点并通过 RedisClusterConfiguration
注入 LettuceConnectionFactory
。
2) 如果我使用 Lettuce 作为直接实现(不是通过 Spring 数据)使用 StatefulRedisClusterConnection
.
以上两个错误可能是什么原因造成的?我更愿意通过使用集群配置端点将 Lettuce 与 Spring 数据一起使用。
下面是使用Spring数据连接到Elasticache Redis集群的解决方案-
使用 ElastiCache 集群配置端点:
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration clusterConfiguration = new
RedisClusterConfiguration();
clusterConfiguration.clusterNode("host", port);
new LettuceConnectionFactory(clusterConfiguration);
}
使用 ElastiCache 节点端点:
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration()
.clusterNode("redis-cluster----0001-001.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-002.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-003.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-004.redis-cluster---.usw2.cache.amazonaws.com",6379);
return clusterConfiguration;
}
感谢 Mark Paluch 在 Spring 数据论坛中回复了我的问题。
这是详细信息 - https://jira.spring.io/browse/DATAREDIS-898
我在集群模式下使用 AWS ElastiCache (Redis)。我有两个连接到 ElastiCache 的实现。其中一种实现方式是直接使用本机 Lettuce 驱动程序,其他使用 Spring 数据并将 Lettuce 作为底层驱动程序。 AWS ElastiCache 具有集群配置端点。我想使用此端点连接到 ElastiCache。我能够使用具有本机 Lettuce 驱动程序实现的集群端点成功连接到 ElastiCache,但是在使用 spring 数据和集群端点
时出现以下错误Spring 数据:1.8.9-RELEASE(不能选择更高版本的 Spring)
生菜:4.5.0-最终版
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
lettuceConnectionFactory.setHostName(<cluster_endpoint>);
lettuceConnectionFactory.setPort();
lettuceConnectionFactory.setUseSsl(Boolean.valueOf(useSsl));
//lettuceConnectionFactory.setPassword(password);
return lettuceConnectionFactory;
}
错误:
Caused by: org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: MOVED 12894 cache---.usw2.cache.amazonaws.com:6379
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:50)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:48)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
它在以下两种情况下工作正常 -
1) 我使用集群节点端点并通过 RedisClusterConfiguration
注入 LettuceConnectionFactory
。
2) 如果我使用 Lettuce 作为直接实现(不是通过 Spring 数据)使用 StatefulRedisClusterConnection
.
以上两个错误可能是什么原因造成的?我更愿意通过使用集群配置端点将 Lettuce 与 Spring 数据一起使用。
下面是使用Spring数据连接到Elasticache Redis集群的解决方案-
使用 ElastiCache 集群配置端点:
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration clusterConfiguration = new
RedisClusterConfiguration();
clusterConfiguration.clusterNode("host", port);
new LettuceConnectionFactory(clusterConfiguration);
}
使用 ElastiCache 节点端点:
@Bean
public RedisClusterConfiguration redisClusterConfiguration() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration()
.clusterNode("redis-cluster----0001-001.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-002.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-003.redis-cluster---.usw2.cache.amazonaws.com",6379)
.clusterNode("redis-cluster----0001-004.redis-cluster---.usw2.cache.amazonaws.com",6379);
return clusterConfiguration;
}
感谢 Mark Paluch 在 Spring 数据论坛中回复了我的问题。 这是详细信息 - https://jira.spring.io/browse/DATAREDIS-898