代码之家  ›  专栏  ›  技术社区  ›  Chaithra Rai

使用生菜配置在springboot中启用Redis群集模式时出现CROSSSLOT密钥错误

  •  0
  • Chaithra Rai  · 技术社区  · 3 年前

    我们刚刚从redisstandalone转移到集群,我们遇到了以下异常:RedisSystemException:执行中出错;嵌套异常为io.lettuce.core.RedisCommandExecutionException:请求中的CROSSSLOT密钥不哈希到同一个插槽。 在进一步深入研究时,我发现当请求中的密钥在redisTemplate.opsForZSet().contersectAndStore/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);
        }
      }
    

    这个概念我理解错了吗?任何可能有效的代码片段示例输入都可能帮助我度过难关?

    0 回复  |  直到 3 年前
        1
  •  0
  •   Chaithra Rai    3 年前

    我试图为一个redis键传递不同的键:value。问题是每次都要传递相同的密钥,而不是冒险更改它

    redisTemplate.opsForValue().set("{someconstantstring}", value;
        
    

    这个博客提供了一个很好的见解: https://hackernoon.com/resolving-the-crossslot-keys-error-with-redis-cluster-mode-enabled