You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid the race condition where INCRBY executes but EXPIRE does not, the recommended approach is to use a Lua script via EVAL. However, this method negatively impacts performance.
Alternatives Considered
It would be beneficial to have a single command that combines both operations—only applying expiration when the record is initially created. Using a transaction isn't ideal because EXPIRE will always execute, unnecessarily updating the TTL.
A clean solution would be to introduce an additional parameter, EX, to the INCR family of commands, similar to how it's used in SET.
Another alternative is to enhance the EXPIRE command by adding an NX option. With NX, EXPIRE would only apply if the key does not already have an expiration, making it more flexible.
The text was updated successfully, but these errors were encountered:
The Problem/Use-Case This Feature Addresses
When using counters, you often need to set them to expire after a certain period. Currently, the only known solution is:
INCRBY
.EXPIRE
.This issue is also discussed in the following resources:
To avoid the race condition where
INCRBY
executes butEXPIRE
does not, the recommended approach is to use a Lua script viaEVAL
. However, this method negatively impacts performance.Alternatives Considered
It would be beneficial to have a single command that combines both operations—only applying expiration when the record is initially created. Using a transaction isn't ideal because
EXPIRE
will always execute, unnecessarily updating the TTL.A clean solution would be to introduce an additional parameter,
EX
, to theINCR
family of commands, similar to how it's used inSET
.Another alternative is to enhance the
EXPIRE
command by adding anNX
option. WithNX
,EXPIRE
would only apply if the key does not already have an expiration, making it more flexible.The text was updated successfully, but these errors were encountered: