Redisson客户端:检索前N个密钥



如何从redison客户端获取N个键的顶部?

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

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

但看起来count-是每个请求加载到Redis的密钥。

如何通过redison客户端从Redis加载前N个密钥?

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)

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

最新更新