Monitor changes to Redis keys and values in real time
实时监控 Redis 键和值的更改
Keyspace notifications allow clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.
Keyspace 通知允许客户端订阅 Pub/Sub 频道,以便接收以某种方式影响 Redis 数据集的事件。
Examples of events that can be received are:
可以接收的事件示例包括:
- All the commands affecting a given key.
影响给定键的所有命令。 - All the keys receiving an LPUSH operation.
所有接收 LPUSH 作的 key。 - All the keys expiring in the database 0.
数据库 0 中过期的所有键。
Note: Redis Pub/Sub is fire and forget; that is, if your Pub/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost.
注意:Redis Pub/Sub 是_即发即弃_ ;也就是说,如果您的 Pub/Sub 客户端断开连接,并在以后重新连接,则在客户端断开连接期间传送的所有事件都将丢失。
Timing of expired events
Keys with a time to live associated are expired by Redis in two ways:
Redis 以两种方式使具有生存时间关联的密钥过期:
- When the key is accessed by a command and is found to be expired.
当密钥被命令访问并发现已过期时。 - Via a background system that looks for expired keys in the background, incrementally, in order to be able to also collect keys that are never accessed.
通过后台系统,该系统在后台以增量方式查找过期的密钥,以便能够收集从未访问过的密钥。
The expired
events are generated when a key is accessed and is found to be expired by one of the above systems, as a result there are no guarantees that the Redis server will be able to generate the expired
event at the time the key time to live reaches the value of zero.
过期
事件是在访问密钥时生成,并且被上述系统之一发现已过期,因此无法保证 Redis 服务器能够在关键生存时间达到零值时生成过期
事件。
If no command targets the key constantly, and there are many keys with a TTL associated, there can be a significant delay between the time the key time to live drops to zero, and the time the expired
event is generated.
如果没有命令持续以密钥为目标,并且有许多密钥与 TTL 相关联,则密钥存活时间降至零的时间与生成过期
事件的时间之间可能存在明显的延迟。
Expired (expired
) events are generated when the Redis server deletes the key and not when the time to live theoretically reaches the value of zero.
过期 (expired
) 事件是在 Redis 服务器删除键时生成,而不是在理论生存时间达到零值时生成。