How to get callback when key expires in REDIS

Question:

I’m developing application using Bottle. In my registration form, I’m confirming email by mail with a unique key. I’m storing this key in REDIS with expiry of 4 days. If user does not confirm email within 4 days, key gets expired. for this, I want to permanently delete the user entry from my database(mongoDB).

Ofcourse I dont require continous polling to my redis server to check whether key exists or not.

Is there any way to get a callback from Redis??

OR is there any other efficient way?

Asked By: Kartik Rokde

||

Answers:

There are no such callbacks in redis (not that I know of).

I would do it like this:

  • when user signs up, put his id into a sorted set where the score is a timestamp (now + 4 days) and member is user id.
  • have a periodic job that gets all records from that sorted set where timestamp is in the past.
  • loop through those user ids and take actions (if he didn’t confirm – delete all user’s data).
Answered By: Sergio Tulentsev

This feature implemented in Redis 2.8, read about it here http://redis.io/topics/notifications

Answered By: Nikita Koksharov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.