Reading — step 1 of 3
Range Queries
~1 min readLists
LRANGE — Querying List Ranges
LRANGE returns a slice of the list without removing elements.
Syntax
LRANGE key start stop — returns elements from index start to stop, inclusive.
Indexing
- 0-based from the left:
0= first,1= second - Negative from the right:
-1= last,-2= second-to-last LRANGE key 0 -1returns all elements
Out of Range
Out-of-range indices are clamped — no error. If start > list length, returns empty array.
RESP Array Format
*3\r\n$5\r\nalice\r\n$3\r\nbob\r\n$7\r\ncharlie\r\n
The *3 prefix says "3 elements follow", then each element is a bulk string.
Non-existing keys return empty array: *0\r\n
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…