由于redis容器中的过期,如何显示干净的日志
How to show clean log due to expired in redis container
我想找到一个解决方案,当缓存在 redis 容器中过期时显示已清理的缓存。有什么办法解决吗?
如果您问我如何知道 Redis 的特定密钥已过期 - 您可以使用密钥空间通知并监听任何事件和日志。
https://redis.io/topics/notifications
一个听众会话
$ redis-cli
127.0.0.1:6379> config set notify-keyspace-events KEex
OK
127.0.0.1:6379> psubscribe '__key*__:*'
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__key*__:*"
3) (integer) 1
#### After waiting for a while...
1) "pmessage"
2) "__key*__:*"
3) "__keyspace@0__:foo"
4) "expired"
1) "pmessage"
2) "__key*__:*"
3) "__keyevent@0__:expired"
4) "foo"
然后创建一个过期的密钥
127.0.0.1:6379> set foo bar EX 2
OK
否则,您可以使用 Prometheus 等各种开源观察工具观察过期或逐出的密钥数量。
我想找到一个解决方案,当缓存在 redis 容器中过期时显示已清理的缓存。有什么办法解决吗?
如果您问我如何知道 Redis 的特定密钥已过期 - 您可以使用密钥空间通知并监听任何事件和日志。
https://redis.io/topics/notifications
一个听众会话
$ redis-cli
127.0.0.1:6379> config set notify-keyspace-events KEex
OK
127.0.0.1:6379> psubscribe '__key*__:*'
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__key*__:*"
3) (integer) 1
#### After waiting for a while...
1) "pmessage"
2) "__key*__:*"
3) "__keyspace@0__:foo"
4) "expired"
1) "pmessage"
2) "__key*__:*"
3) "__keyevent@0__:expired"
4) "foo"
然后创建一个过期的密钥
127.0.0.1:6379> set foo bar EX 2
OK
否则,您可以使用 Prometheus 等各种开源观察工具观察过期或逐出的密钥数量。