密钥过期事件 [英] Event on key expire

查看:90
本文介绍了密钥过期事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 redis 中是否有一项功能可以让我获取所有过期的密钥(我的意思是某种事件,这让我有机会收回所有过期记录).它的目的是将旧值保存到另一个数据库中.我听说可以使用发布机制,但 google 无法帮助我们实现这个想法.

I wonder if there is a feature in redis that allow me to get all expired keys (I mean some kind of event, that gives me an opportunity to take back all expire records). The purpose of it is in saving old values into another database. I've heard that it's possible using publishing mechanism, but google can't help we with this idea.

推荐答案

redis 的当前开发版本包含一个新功能:键空间通知.文档:http://redis.io/topics/notifications

Current development version of redis contains a new feature: keyspace notifications. Documentation: http://redis.io/topics/notifications

密钥空间通知允许客户端订阅 Pub/Sub 频道,以便以某种方式接收影响 Redis 数据集的事件.

Keyspace notifications allows clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.

可能接收的事件示例如下:

Examples of the events that is possible to receive are the following:

  • 影响给定键的所有命令.
  • 接收 LPUSH 操作的所有键.
  • 数据库 0 中所有过期的键.

希望能尽快稳定下来.

顺便说一句,它在帮助您保存过期键的值方面不会很有用.当过期事件被触发时,该值已经消失了.

BTW, it won't be very useful in helping you save values of expired keys. When expiration event is fired, the value is gone already.

这篇关于密钥过期事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆