# LRANGE

> Get a range of elements from a list by index.

URL: https://docs.hotkv.com/commands/lrange/

```
LRANGE key start stop
```

- Group: List
- Complexity: O(S+N) where S is the distance of start from the nearer end and N is the number of elements returned
- HotKV Cloud: all plans
- On-Premise: no license needed

`LRANGE` returns the elements of the list at `key` from index `start` to index
`stop`, both included. Indexes start at `0`. Negative indexes count from the
end: `-1` is the last element, `-2` the one before it, and so on.

Out-of-range indexes are not an error. A `stop` past the end is treated as the
last element, and a `start` past the end (or after `stop`) gives an empty
array. `LRANGE key 0 -1` returns the whole list.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array of bulk strings | Same |
| Key does not exist or the range is empty | Empty array | Same |

Errors:

- `ERR value is not an integer or out of range` if `start` or `stop` is not an
  integer. This is checked before the key is looked up.
- `WRONGTYPE` if `key` holds a value that is not a list.

## Examples

```
127.0.0.1:6379> RPUSH letters a b c d e
(integer) 5
127.0.0.1:6379> LRANGE letters 0 1
1) "a"
2) "b"
127.0.0.1:6379> LRANGE letters -2 -1
1) "d"
2) "e"
127.0.0.1:6379> LRANGE letters 3 100
1) "d"
2) "e"
127.0.0.1:6379> LRANGE letters 10 20
(empty array)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[LINDEX](https://docs.hotkv.com/commands/lindex/index.md), [LLEN](https://docs.hotkv.com/commands/llen/index.md), [LTRIM](https://docs.hotkv.com/commands/ltrim/index.md),
[LPOS](https://docs.hotkv.com/commands/lpos/index.md)