Question

I plan to use redis as a cache where every key will have an expire set, I used the following configration in redis.conf:

maxmemory 2gb
maxmemory-policy allkeys-lru

What the problem is how to persist the expired keys to another database like MongoDB(or what ever database) which could stored the keys in the disk. The requirement is following:

1.when I query a "hot key"(which recently ofen used), I could quickly get the result from redis if redis has the key, otherwise I could get the key from the other database which stored the key in the disk. 2.each keys have their life time. When there were keys expired in redis, the other database should stored the expired keys.

"When Redis is used as a cache in this way, if the application also requires the use Redis as a store, it is strongly suggested to create two Redis instances, one as a cache, configured in this way, and one as a store, configured accordingly to your persistence needs and only holding keys that are not about cached data." quote by http://redis.io/topics/config

what my problem is to persist the expired keys to another database(stored keys in disk) instead of redis.

Was it helpful?

Solution

You need to enable notify-keyspace-events http://redis.io/topics/notifications

And capture the expire/evict events.

Then use "psubscribe" to listen for "del" events and send those keys off to another database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top