How to get callback when key expires in REDIS
Asked Answered
T

2

33

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?

Tallie answered 1/11, 2012 at 9:56 Comment(1)
Please see Notification of key expiration in redis python for an up-to-date answer.Spectroheliograph
B
32

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

Biramous answered 20/1, 2014 at 5:29 Comment(0)
G
12

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).
Ganda answered 1/11, 2012 at 10:1 Comment(2)
More information in #11810520Opprobrium
Great technique, something I will copy if you do not mind ^_^Moonshiner

© 2022 - 2024 — McMap. All rights reserved.