Redis: Feature request: Allow exclusive start/stop in _REVRANGE and _RANGE"

Created on 11 Nov 2019  路  3Comments  路  Source: redis/redis

It is unlikely to have a key with the maximum integer on the secondary id value:
1573474540414-18446744073709551615,
but if we want to use XREVRANGE, to make sure that we are iterating correct, the previous possible key for:
1573474540414-0 would be: 1573474540413-18446744073709551615

So, to correct use XREVRANGE:

127.0.0.1:6379> xrevrange cities + - COUNT 2
1) 1) "1573474557101-0"
   2) 1) "locatin"
      2) "victoria"
      3) "user"
      4) "2444"
      5) "browser"
      6) "opera"
      7) "version"
      8) "87"
2) 1) "1573474540414-0"
   2) 1) "locatin"
      2) "vancouver"
      3) "user"
      4) "1234"
      5) "browser"
      6) "firefox"
      7) "version"
      8) "20"

the next value to be used is:

127.0.0.1:6379> xrevrange cities 1573474540413-18446744073709551615 - COUNT 2
xrevrange cities 1573474540413-18446744073709551615 - COUNT 2
1) 1) "1573474521406-0"
   2) 1) "locatin"
      2) "calgary"
      3) "user"
      4) "8899"
      5) "browser"
      6) "edge"
      7) "version"
      8) "14"
2) 1) "1573474497649-0"
   2) 1) "locatin"
      2) "edmonton"
      3) "user"
      4) "1234"
      5) "browser"
      6) "chrome"
      7) "version"
      8) "99"

My suggesting os to create a pattern for the previous keys after or before a particular one:
[1573474540414-0 would be the previous one and 1573474540414-0] would be the next one.

making more simple to handle xrange and xrevrange.

feature help-wanted needs-coding

Most helpful comment

Status:
Implementation effort looks low, we need to support both inclusive and exclusive boundaries on the xrange command.

Leo seems to have provided the consistent type of implementation. We will extend it to check if the first character is a (, which would indicate that this is an inclusive search.

All 3 comments

My two cents:

  • Note the previous to 414-0 would be: 413-18446744073709551615, not the 9...9. It is the max unsigned 64-bit integer.
  • Consider renaming the issue to "Feature request: Allow exclusive start/stop in _REVRANGE and _RANGE", as applicable to streams and sorted sets.
  • If implemented, let's be consistent. ZRANGEBYLEX already has this: "Valid start and stop must start with ( or [, in order to specify if the range item is respectively exclusive or inclusive.". And ZRANGEBYSCORE has "By default, the interval specified by min and max is closed (inclusive). It is possible to specify an open interval (exclusive) by prefixing the score with the character (."

@leomurillo Thanks for sharing this, It would be great if this feature is implemented. :)

Status:
Implementation effort looks low, we need to support both inclusive and exclusive boundaries on the xrange command.

Leo seems to have provided the consistent type of implementation. We will extend it to check if the first character is a (, which would indicate that this is an inclusive search.

Was this page helpful?
0 / 5 - 0 ratings