如何在密钥在REDIS中过期时获得回调

时间:2021-09-11 02:12:58

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

我正在用瓶子开发应用程序。在我的注册表中,我正在用唯一的密钥通过邮件确认电子邮件。我把这把钥匙储存在REDIS,期限是4天。如果用户在4天内没有确认邮件,密钥将过期。为此,我希望永久地从我的数据库(mongoDB)中删除用户条目。

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

当然,我不需要对我的redis服务器进行持续轮询来检查键是否存在。

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

有办法从Redis那里得到回调吗?

OR is there any other efficient way?

或者还有其他有效的方法吗?

2 个解决方案

#1


12  

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

这个在Redis 2.8中实现的特性,请阅读http://redis.io/topics/notifications

#2


9  

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

在redis中没有这样的回调(我不知道)。

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.
  • 当用户注册时,将其id放入一个排序集,其中的分数是一个时间戳(现在+ 4天),成员是用户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).
  • 循环这些用户id并采取行动(如果他没有确认-删除所有用户的数据)。

#1


12  

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

这个在Redis 2.8中实现的特性,请阅读http://redis.io/topics/notifications

#2


9  

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

在redis中没有这样的回调(我不知道)。

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.
  • 当用户注册时,将其id放入一个排序集,其中的分数是一个时间戳(现在+ 4天),成员是用户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).
  • 循环这些用户id并采取行动(如果他没有确认-删除所有用户的数据)。