Use LPOS to find the position of an element in a list.
The scan starts at the head and, by default, reports the index of the first match or null when there is none. RANK selects which match to report: RANK 2 skips to the second occurrence, and a negative rank searches backwards from the tail, so RANK -1 finds the last occurrence. COUNT returns that many matching indexes instead of just one, and COUNT 0 returns all of them. MAXLEN limits how many elements are compared, which bounds the cost of the search on a long list at the price of possibly missing matches beyond that point.
It is the read-only way to locate a value before acting on it with LSET or LREM.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
<element> | Yes | No | Element value to search for. |
RANK <rank> | No | No | Which match to return; negative values search from the tail. |
COUNT <num-matches> | No | No | Number of matches to return; 0 returns every match. |
MAXLEN <len> | No | No | Maximum number of entries to keep in the stream. |
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Null bulk string or null array, Integer, or array of integer positions |
| RESP3 | Null, Integer, or array of integer positions |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.