【问题标题】:redis retrieve data at suscribe when key expire当密钥过期时,redis 在 suscribe 检索数据
【发布时间】:2023-02-17 07:09:39
【问题描述】:

我有以下代码,用于处理 redis 中的密钥过期时间:

r.config_set('notify-keyspace-events', 'Ex')
    pubsub.psubscribe(**{"__keyevent@0__:expired": event_handler})
    pubsub.run_in_thread(sleep_time=0.01)

def event_handler(msg):
    try:
        print(msg)
        key = msg["data"].decode("utf-8")
        print(key)
    except Exception as e:
        print(e)

问题是我只得到密钥,而不是过期密钥的值。

有没有办法得到这些数据?

谢谢

【问题讨论】:

  • 不,目前没有这样的选项。

标签: python redis py-redis


【解决方案1】:

创建另一个密钥,例如实际上已经过期的“mykey.shadow”。当它过期时,取回真正的密钥和存储的值,然后删除它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 2020-04-19
    • 2016-04-25
    • 2023-03-04
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2012-08-04
    相关资源
    最近更新 更多