pythonredisjedisfoundationdb

What is the Redis equivalent of TransactionDB's getRange?


The transactionDB python api says that,

Database.get_range(begin, end[, limit, reverse, streaming_mode])

Returns all keys k such that begin <= k < end and their associated values as a list of KeyValue objects. Note the exclusion of end from the range.

This read is fully synchronous.

I want something equivalent in Redis. I looked at lrange and zrange functions but don't think that they are similar.


Solution

  • TL;DR there isn't a direct equivalent and scanning the entire key space is always slow(er) - you should avoid it unless your intent is getting most/all of the keys anyway.

    There are two Redis commands that allow you to scan the keyspace - one is called SCAN and the other one should not be mentioned nor used for anything but development. Unlike what you're after, however, these commands: 1. Do not work on ranges of keys, but rather on glob-like patterns 2. Do not return the associated value, you have to specifically read it

    Generally speaking, you should refrain from practicing such read patterns unless you mean it - in most cases, you want the responses fast and cheap, so a full scan is almost always not the right way,