1

In redis docs, it is stated that keys command should not be used in production, since it blocks other processes while executing, it is better to use scan iteration over all keys with some batch size. I've read in docs that redis use hash index, so I assume it can't use it for range queries like scan and keys.

But our system is done in such a way that we need to use scans extensively. Is it ok, could it decrease the performance of hash queries significantly?

asked Jan 12, 2021 at 15:37

1 Answer 1

2

Note Redis is single-thread, so any operation could block another.

(It tried to address this issue in its recent release by delegating the time spent reading and writing to I/O sockets over to other threads, so the Redis process can devote more cycles to manipulating, storing, and retrieving data—boosting overall performance. You need benchmark by yourself on your own use case though.)

I've read in docs that redis use hash index, so I assume it can't use it for range queries

There are multiple data types in Redis, and if you are using sorted set, zrange returns the specified range of elements.

Is it ok, could it decrease the performance of hash queries significantly?

Not sure about your use case, but I think scan is better used for a matching, for example in Java

KeyScanCursor<String> cursor = sync.scan(ScanArgs.Builder.limit(1000).match(wildMatch));

and yes scan could be very slow and returns very few keys per cursor. So as above example shows, it's better to set a max key number to avoid it taking very long time and/or triggering the request resource limit.

Therefore, you can do something like

while (!cursor.isFinished() && fetchedResult.size() < keyNumber) 
{
 fetchedResult.addAll(cursor.getKeys());
 cursor = sync.scan(cursor, ScanArgs.Builder.matches(wildMatch));
}
answered Jan 12, 2021 at 16:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.