redis-lrange
Get the elements of a Redis list in the given range, one row per element.
Syntax
redis-lrange profile=STRING key=STRING [start=INT] [stop=INT]
Options
- profile=STRING
- Required. Name of the Redis connect profile. Either a Redis Client (Standalone) or a Redis Client (Sentinel) profile is accepted. Example: profile=my_redis
- key=STRING
- Required. Redis list key to LRANGE. Example: key=queue:jobs
- start=INT
- Optional. Start index. Negative values count from the end. (Default: 0)
- stop=INT
- Optional. Stop index, inclusive. (Default: -1, the last element)
Output fields
| Field | Type | Name | Description |
|---|---|---|---|
| key | String | Key | Redis list key |
| index | Integer | Index | Zero-based position within the returned range |
| value | String | Value | List element |
| _error | String | Error | Error message for command failure. Absent on success |
Error codes
Parse errors
| Error message | Cause | Resolution |
|---|---|---|
| No available Redis profile | No profile with the given name exists, or the current account is not granted access to it. | Check the profile name and grant the account access to the profile. |
| profile option is required | The profile option is missing or empty. | Specify profile=profile_name. |
| key option is required | The key option is missing or empty. | Specify key=key_name. |
| start and stop options must be integers | The start or stop value is not an integer. | Specify integers, e.g. start=0 stop=9 |
Runtime errors
| Error message | Cause | Resolution |
|---|---|---|
| (_error field of the output row) | A Redis error occurred, such as a connection failure, authentication failure, timeout or WRONGTYPE. The query does not abort; one row holding only key and _error is returned. | Check the message in the _error field, the connection settings and the key type. |
Description
Reads list elements with the Redis LRANGE command and outputs one row per element. index is the position within the returned range, not within the whole list, so it starts at 0 even if start is specified. It takes no pipe input.
If the list key does not exist or the range holds no elements, no rows are output. A key of a non-list type outputs a WRONGTYPE error in the _error field. All elements in the range are fetched at once, so limit very large lists with start and stop.
Examples
Example: Reading the first 10 items of a job queue
Situation: Check the first 10 elements of the list queue:jobs.
Expected result:
| key | index | value |
|---|---|---|
| queue:jobs | 0 | job-1003 |
| queue:jobs | 1 | job-1002 |
Interpretation: Elements added with LPUSH are stacked at the head, so index 0 is the most recently pushed value.