I have a redis list I have created, I am using it as a queue at the moment that reverses once in a while. My problem is that I would like to be able to get the index of an i
Use sorted sets to implement a queue.
Add members and use timestamp as score.
> ZADD queue 1326990501 foo 1326990502 bar 1326990503 baz 1326990504 qux
(integer) 4
You can return members in FIFO and LIFO order by the use of ZRANGE and ZREVRANGE respectively.
FIFO:
> ZRANGE queue 0 0
"foo"
LIFO:
> ZREVRANGE queue 0 0
"qux"
To find the index of a member use ZRANK. ZRANK op is O(log(N))
> ZRANK queue bar
(integer) 1