Prem Prem - 2 months ago 7
Node.js Question

How to get index of the lpop'ed or rpop'ed item of Redis

I am working on real-time analytics using

Redis
as in-memory database. In my analytics, I keep on doing
rpop
on growing
Redis-list
to perform analytics on every
rpop'ed
items. To perform clean-up of
Redis-list
and not to allow growing up enormously, I should extract and make a back-up of
Redis-list
at
23:59:59
of every day.


If I blindly do a clean-up on Redis-list exactly at
23:59:59
, there are possiblity that few elements which are not
lpop'ed
or
rpop'ed
may get cleaned-up. Index is the best option to clean-up the growing list while it's being analyzed.


Is there any
Redis-commands
to get the index of
lpop'ed
or
rpop'ed
item?

Answer

if I understand, when you pop list, you want value and index of value. In case of lpop, index is alway 0. In case of rpop, only way is use llen.

To run llen and rpop in one time, you need use transaction like :

MULTI
LLEN my-queue
RPOP myqueue
EXEC

Regards,

Comments