【问题标题】:Redisson client: retrieve top N keysRedisson 客户端:检索前 N 个键
【发布时间】:2020-09-17 14:11:35
【问题描述】:

如何从redisson client 获取 N 个键的顶部?

我在getKeysByPattern() 方法中找到了下一个签名:

Iterable<String> getKeysByPattern(String pattern, int count);

但看起来像 count - 是根据对 Redis 的请求加载的密钥。

如何通过 redisson 客户端从 Redis 加载前 N 个键?

【问题讨论】:

    标签: redis redisson


    【解决方案1】:

    getKeysByPattern() 在这种情况下无效,对吧。

    这里最好使用lua脚本:

    val luaScript = "return {redis.call('SCAN',ARGV[1],'MATCH',ARGV[2],'COUNT',ARGV[3])}"
    var cursor = 0
    do {
      val data = redissonClient
                    .getScript(StringCodec.INSTANCE)
                    .eval(RScript.Mode.READ_ONLY,
                            luaScript,
                            RScript.ReturnType.MAPVALUELIST,
                            listOf(),
                            cursor,
                            "some-pattern",
                            batchSize)
    
    
      val redistListData = (data[0][1] as List<String>)
      cursor = data[0][0].toInt()
    } while (cursor != 0)
    

    【讨论】:

      【解决方案2】:

      这种情况你需要使用RKeys.getKeysWithLimit(String pattern, int limit)方法。

      【讨论】:

        猜你喜欢
        • 2019-05-04
        • 2018-05-31
        • 2020-12-14
        • 2016-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-24
        相关资源
        最近更新 更多