Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] INCRBY and EXPIRE #1818

Open
silviucpp opened this issue Mar 4, 2025 · 0 comments
Open

[NEW] INCRBY and EXPIRE #1818

silviucpp opened this issue Mar 4, 2025 · 0 comments
Labels
client-changes-needed Client changes are required for this feature

Comments

@silviucpp
Copy link

silviucpp commented Mar 4, 2025

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:

  1. Call INCRBY.
  2. If the returned result equals the initial value (indicating a new record was created), call EXPIRE.

This issue is also discussed in the following resources:

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.

@silviucpp silviucpp changed the title [NEW] INCRBY and EXPIRE Mar 4, 2025
@silviucpp silviucpp changed the title INCRBY and EXPIRE [NEW] INCRBY and EXPIRE Mar 6, 2025
@asafpamzn asafpamzn added the client-changes-needed Client changes are required for this feature label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client-changes-needed Client changes are required for this feature
Projects
None yet
Development

No branches or pull requests

2 participants