How to get callback when key expires in REDIS

痴心易碎 提交于 2019-11-29 02:32:56

问题


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?


回答1:


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




回答2:


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).


来源:https://stackoverflow.com/questions/13174615/how-to-get-callback-when-key-expires-in-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!