List

LPOS

Returns the index of matching elements inside a list.

Arguments

keybodystringrequired

The key of the list.

elementbodyunknownrequired

The element to match.

optsbody
rankbodynumber

The rank of the element to match. If specified, the element at the given rank is matched instead of the first element.

countbodynumber

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

maxLenbodynumber

Limit the number of comparisons to perform.

Response

number | number[]required

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

Example
await redis.rpush("key", "a", "b", "c"); const index = await redis.lpos("key", "b");console.log(index); // 1
With Rank
await redis.rpush("key", "a", "b", "c", "b"); const index = await redis.lpos("key", "b", { rank: 2 });console.log(index); // 3
With Count
await redis.rpush("key", "a", "b", "b");const positions = await redis.lpos("key", "b", { count: 2 });console.log(positions); // [1, 2]
Loading search…