Improve performance of RedissonMap.keySet(batchSize) by using NOVALUES with HSCAN
Is your feature request related to a problem? Please describe.
We have a single hash in redis of length 6000, and its total memory size is 1GB. We used RMap.keySet(1000) to stream all keys of that hash into the app, but it took 6 seconds to finish. It doesn't help if we use larger batch size of 6000 or smaller. If I use readAllKeySet, it finishes around 20ms.
It looks RMap.keySet(batchSize) uses HSCAN in a lua script here https://github.com/redisson/redisson/blob/65517022236c6721eaf480d71bcdb9dd02b8132f/redisson/src/main/java/org/redisson/RedissonMap.java#L1556
It has to traverse the internal hash table structure (or listpack/ziplist), deserialise entries to check them, even though the Lua script only returns keys. With a 1 GB hash the internal data structure is large and each scan traversal has meaningful CPU cost on the Redis server.
For readAllKeySet, it uses HKEYS which is much faster for this case.
Describe the solution you'd like
Not sure if it will help, if we only need keys of the hash, can we use NOVALUES option in lua script with hscan?
Describe alternatives you've considered
Source: redisson/redisson