List

LPOS

Returns the index of matching elements inside a list.

Arguments

keybodystrrequired

The key of the list.

elementbodyunknownrequired

The element to match.

rankbodyint

Which match to return. 1 to return the first match, 2 to return the second match, and so on. 1 by default.

countbodyint

The maximum number of elements to match. If specified, an array of elements is returned instead of a single element.

maxlenbodyint

Limit the number of comparisons to perform.

Response

int | List[int]required

The index of the matching element or an array of indexes if count is specified.

Example
redis.rpush("key", "a", "b", "c"); assert redis.lpos("key", "b") == 1
With Rank
redis.rpush("key", "a", "b", "c", "b"); assert redis.lpos("key", "b", rank=2) == 3
With Count
redis.rpush("key", "a", "b", "b")assert redis.lpos("key", "b", count=2) == [1, 2]
Loading search…