我们刚刚从redis单机迁移到集群,遇到了以下异常:RedisSystemException:执行时出错;嵌套异常是 io.lettuce.core.RedisCommandExecutionException:请求中的 CROSSSLOT 键不会散列到同一插槽。 进一步深入研究后,我发现当请求中的键在 redisTemplate.opsForZSet().intersectAndStore / redisTemplate.opsForZSet().differenceAndStore 和类似的联合交集操作期间未散列到同一插槽时,就会出现此问题。
我遇到了这个称为主题标签的概念,但我没有找到通过我的代码解决它的方法
@LogMethodCall
public String getValueByKey(String key) {
if (BooleanUtils.isTrue(keyExists(key))) {
return redisTemplate.opsForValue().get(key+"{someconstantstring}");
}
return null;
}
@LogMethodCall
public void save(String key, String value) {
if (StringUtils.isNotEmpty(key)) {
redisTemplate.opsForValue().set(key+"{someconstantstring}", value);
}
}
@LogMethodCall
public void saveWithExpiryInMinutes(String key, String value, long expiryTime) {
if (StringUtils.isNotEmpty(key)) {
redisTemplate.opsForValue().set(key+"someconstantstring", value, expiryTime, TimeUnit.MINUTES);
}
}
@LogMethodCall
public void saveWithExpiryInSeconds(String key, String value, long expiryTime) {
if (StringUtils.isNotEmpty(key)) {
redisTemplate.opsForValue().set(key+"{someconstantstring}", value, expiryTime, TimeUnit.SECONDS);
}
}
我对这个概念的理解是否错误?任何带有可能有效的代码片段示例的输入可能会帮助我解决这个问题?
我试图为一个 redis key:value 传递不同的键。问题是每次都传递相同的密钥,而不是冒险更改它。例如
redisTemplate.opsForValue().set("{someconstantstring}", value;
此博客对此提供了很好的见解:https://hackernoon.com/resolving-the-crossslot-keys-error-with-redis-cluster-mode-enabled
我有类似的问题,但不知道如何编辑 redis 函数,因为我使用的是 Spring Security:
Spring Boot / Spring Security 应用程序,出现 AWS Redis Elasticache 生产错误(失败:对等方重置连接和 CROSSSLOT 错误)