2

I have a redis cache where each key is of type list and from redisson i want to make a map of each list key and their size...

Below code is working fine but I want to make single call to redis cache.

Iterable<String> keys = redissonClient.getKeys().getKeysByPattern(keyPattern);


    Map<String, Integer> map = new HashMap<>();
    for (String key : keys) {
        map.put(key, redissonClient.getList(key).size());
    }
    return map;
}

Thanks in advance

Satish Bhuria
  • 81
  • 2
  • 13

1 Answers1

0
    Iterable<String> keys = redissonClient.getKeys().getKeysByPattern(keyPattern);

    var rBarch = redissonClient.createBatch();
    Map <String, Integer> map = new HashMap<>();
    for (String key : keys) {
        rBarch.getList(key).sizeAsync().whenComplete((integer, throwable) -> map.get(key, integer));
    }
    rBarch.execute();
    return map;
Venkov
  • 11
  • 1