Search code examples
redisspring-data-redis

Redis key expire event through EXPIREAT command with past timestamp


According to redis doc:

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.

While setting past timestamp, I'm getting exactly same behavior as per doc except there is no key expiry event thrown.

redis> SET mykey "Hello"
"OK"
redis> EXISTS mykey
(integer) 1
redis> EXPIREAT mykey 1293840000
(integer) 1
redis> EXISTS mykey
(integer) 0

It throws key expiry event upon key expire when I set future timestamp in EXPIREAT command.

So is it not supported to get key expiry event while setting past timestamp through EXPIREAT?


Solution

  • In your case, there's no expire event.

    So is it not supported to get key expiry event while setting past timestamp through EXPIREAT?

    In fact, It depends.

    If your Redis is loading data or it's a slave, Redis sets expiration for the given key, and publishes an expire event. Otherwise, Redis deletes or unlinks the given key, and publishes a del event.

    So, in your case, you'll get a del event instead.