Hi,
there is no efficient way to iterate on the whole database with Redis.
The KEYS command will block the instance when you have a
significant number of keys. So you should not use it if your
application is supposed to be always responsive.
If you have the memory space, you can start a slave and iterate
using KEYS on the slave while still updating the master, but
it can be tricky to guarantee the consistency.
Rather than scanning the whole database like a garbage collector,
it is probably more sensible to evaluate whether the objects should
be discarded at set/update time, by posting events to a queue
(i.e. a Redis list) A pool of worker processes can dequeue those
events and then analyze the objects and eventually delete them ...
Regards,
Didier.