Skip to content

Conversation

antonio-tomac
Copy link
Contributor

@antonio-tomac antonio-tomac commented Nov 6, 2017

It is known that using Jedis.keys("*") is bad, especially if key-space is big.
So, alternative is to use Jedis.scan() to avoid many problems with keys command.
But, using scan commands is somewhat cumbersome because we need to deal with cursors which can look ugly and obfuscate application logic with this technical detail.

I've implemented a class ScanCursor for easier/nicer iteration using SCAN, SSCAN, ZSCAN and HSCAN command.
Example usage is:

Jedis jedis = ...;
for (String key : ScanCursor.builder(jedis).pattern("prefix*").scan()) {
    //do something with each matched key
}

We are using that ScanCursor in production for a quite a while.
I've added support for binary iteration for completeness of this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants