2

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.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
PDK
  • 138
  • 5

2 Answers2

2

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,

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • Thanks for responding. I'd like to ask a probably stupid question: why shouldn't the *keys* command be used in production? I have a use case where the *keys* fits quite well. – PDK Aug 31 '16 at 01:04
0

Sorted sets allow you to query by a range. If you're storing say an object, you can use the sorted set to get the desired object ID's, then lookup the object information from a hash with hget/hgetall.

Chris Tanner
  • 1,624
  • 1
  • 12
  • 20