I found an interesting article on twitter, https://ably.com/blog/redis-keys-do-not-expire-atomically.
It seems weird that we advertise scripting as an "atomic" operation, but time is passing. I think we should consider changing all of the time based operations so that they all "take" place at the start of the script.
Comment From: enjoy-binbin
i can recall this one, TTL, recently discussed here: https://github.com/redis/redis/pull/10080#issuecomment-1008801617
Comment From: oranagra
I think that in #9194 i considered to handle that (i.e. to completely pin the time) but eventually didn't. so anyway, i support that idea.
Comment From: Jeremy-Run
If the user can specify that a RedisObject expires at a certain time, does that solve the "atomic" operation problem?
Comment From: enjoy-binbin
@Acm77 We do have the EXPIREAT and PEXPIREAT, can specify a key expires at a certain time.
For the record, the remaining commands I can think of now that need to be processed are: - TTL and PTTL - SET key value EX/PX - EXPIRE and PEXPIRE - GETEX - SETEX and PSETEX - EXPIRETIME and PEXPIRETIME
127.0.0.1:6379> DEBUG set-disable-deny-scripts 1
OK
# TTL use the block time
127.0.0.1:6379> eval "redis.call('set', 'a', 'b', 'ex', '2') redis.call('debug', 'sleep', 1.1) return redis.call('pttl', 'a')" 0
(integer) 2000
(1.10s)
# SET EX use the block time
127.0.0.1:6379> eval "redis.call('set', 'foo', '1', 'ex', '2') redis.call('debug', 'sleep', 1.1) redis.call('set', 'bar', '1', 'ex', '2') return {redis.call('pexpiretime', 'foo'), redis.call('pexpiretime', 'bar')}" 0
1) (integer) 1643252030373
2) (integer) 1643252030373
(1.10s)
# EXPIRE use the block time
127.0.0.1:6379> eval "redis.call('set', 'foo', '1') redis.call('expire', 'foo', 1) redis.call('debug', 'sleep', 1.1) redis.call('set', 'bar', '2') redis.call('expire', 'bar', 1) return {redis.call('pexpiretime', 'foo'), redis.call('pexpiretime', 'bar')}" 0
1) (integer) 1643252840867
2) (integer) 1643252840867
(1.10s)
Comment From: Jeremy-Run
@enjoy-binbin Good, looks like you've stopped time in scripts. But does the same feature apply to master/slave replication?
Comment From: enjoy-binbin
@Acm77 IIRC, we will propagate it as PXAT, like if we use EXPIRE, it will became PEXPIREAT millisecond. Or if we use SET EX, it will become SET PXAT millisecond
Comment From: yossigo
I also think scripts should not see wall clock time changing.