通过具有过去时间戳的 EXPIREAT 命令的 Redis 密钥过期事件
Redis key expire event through EXPIREAT command with past timestamp
根据 redis 文档:
EXPIREAT has the same effect and semantic as EXPIRE, but instead of
specifying the number of seconds representing the TTL (time to live),
it takes an absolute Unix timestamp (seconds since January 1, 1970). A
timestamp in the past will delete the key immediately.
在设置过去的时间戳时,除了没有抛出密钥过期事件外,我得到的行为与文档完全相同。
redis> SET mykey "Hello"
"OK"
redis> EXISTS mykey
(integer) 1
redis> EXPIREAT mykey 1293840000
(integer) 1
redis> EXISTS mykey
(integer) 0
当我在 EXPIREAT
命令中设置未来时间戳时,它会在密钥过期时抛出密钥过期事件。
那么是不是不支持通过EXPIREAT
设置过去的时间戳获取key过期事件?
在你的例子中,没有过期事件。
So is it not supported to get key expiry event while setting past timestamp through EXPIREAT?
事实上,这取决于。
如果您的 Redis 正在加载数据或者它是从服务器,Redis 会为给定的键设置过期时间,并发布一个 expire 事件。否则,Redis 删除或取消链接给定的键,并发布一个 del 事件。
因此,在您的情况下,您将获得 del 事件。
根据 redis 文档:
EXPIREAT has the same effect and semantic as EXPIRE, but instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp (seconds since January 1, 1970). A timestamp in the past will delete the key immediately.
在设置过去的时间戳时,除了没有抛出密钥过期事件外,我得到的行为与文档完全相同。
redis> SET mykey "Hello"
"OK"
redis> EXISTS mykey
(integer) 1
redis> EXPIREAT mykey 1293840000
(integer) 1
redis> EXISTS mykey
(integer) 0
当我在 EXPIREAT
命令中设置未来时间戳时,它会在密钥过期时抛出密钥过期事件。
那么是不是不支持通过EXPIREAT
设置过去的时间戳获取key过期事件?
在你的例子中,没有过期事件。
So is it not supported to get key expiry event while setting past timestamp through EXPIREAT?
事实上,这取决于。
如果您的 Redis 正在加载数据或者它是从服务器,Redis 会为给定的键设置过期时间,并发布一个 expire 事件。否则,Redis 删除或取消链接给定的键,并发布一个 del 事件。
因此,在您的情况下,您将获得 del 事件。