java - 集群模式下的 Redis Pfcount

标签 java spring caching redis

我有以下错误,Redis 强制我对同一节点的键进行计数。 是否有一种新的现代方法来处理 Redis 中的这种缺失功能?

org.springframework.dao.InvalidDataAccessApiUsageException: All keys must map to same slot for pfcount in cluster mode.
        at org.springframework.data.redis.connection.jedis.JedisClusterConnection.pfCount(JedisClusterConnection.java:3610)
        at org.springframework.data.redis.core.DefaultHyperLogLogOperations$2.doInRedis(DefaultHyperLogLogOperations.java:68)
        at org.springframework.data.redis.core.DefaultHyperLogLogOperations$2.doInRedis(DefaultHyperLogLogOperations.java:64)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
        at org.springframework.data.redis.core.DefaultHyperLogLogOperations.size(DefaultHyperLogLogOperations.java:64)

Spring 源代码:

@Override
   public long countAll(List<String> keys) {
      StopWatch stopWatch = new StopWatch();
      stopWatch.start();
      LOGGER.debug("Calculating keys -> {} ", keys);
      long size = 0;
      try {
         size = hyperLogLogOperations.size(keys.toArray(new String[0]));
         redisInTrouble = false;
      } catch (Exception e) {
         LOGGER.error("Having Redis Error with key: {}", keys, e);
         redisInTrouble = true;
      } finally {
         metricObserver.observe(SummaryMetric.REDIS_RESPONSE_PFCOUNT_TIME, stopWatch.getTotalTimeMillis());
         stopOrStartKafkaUpOnRedisError();
      }
      return size;
   }

这里是redis-cli提示符:

172.18.182.82:6379> pfcount XMPP-LI-09270934
(integer) 4
172.18.182.82:6379> pfcount XMPP-LI-09270936
(error) MOVED 3842 172.18.182.82:7379
172.18.182.82:6379> pfcount XMPP-LI-09270936 XMPP-LI-09270934 
(error) CROSSSLOT Keys in request don't hash to the same slot

最佳答案

通过将键括在 {} 中强制键位于同一槽中。例如,pfcount {XMPP-LI}-09270936 {XMPP-LI}-09270934

关于java - 集群模式下的 Redis Pfcount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52607154/

相关文章:

java - 使用正则表达式中的反向引用动态替换文本

java - 键盘隐藏 fragment 中的内容,我需要调整框架布局的大小,以便底部位于键盘上方,现在可以滚动

java - Spring 3+如何 Autowiring 相互使用的bean?

python - 无法启动 Carbon - 12.04 - Python 错误 - ImportError : cannot import name daemonize

c# - 如何使用 Reactive Extensions 来缓存、节流和中继多个事件?

java - java8中如何使用peek()和filter()?

java - 当我不打印字符串时,用Java格式化它

java - Spring Oauth2 隐式流程

java - 如何记录 Spring Data JPA 存储库方法执行时间?

java - Quarkus Panache Hibernate : How to clear the cache, 使实体世界与数据库状态匹配?