LPOS
Since 1.1.0Lists
Syntax
LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]Returns the index of an element equal to element in the list at key.
Options
| Option | Effect |
|---|---|
RANK rank | Return the rank-th match: 2 is the second from the head, -1 the last. |
COUNT num-matches | Return up to this many matches, as an array; 0 means all of them. |
MAXLEN len | Look at no more than the first len elements. |
Reply
- The index, or
nilif there is no match. - With
COUNT: an array of indexes, empty if there is no match.
Examples
> RPUSH p a b c b d b
(integer) 6
> LPOS p b
(integer) 1
> LPOS p b RANK -1
(integer) 5
> LPOS p b COUNT 0
1) (integer) 1
2) (integer) 3
3) (integer) 5
> LPOS p b COUNT 2 MAXLEN 3
1) (integer) 1