The problem/use-case that the feature addresses
We're heavy users of Redis, with a large number of instances deployed in our production environment. In our daily work, we frequently encounter a common business need: combining INCR
with EXPIRE
.
For example, in a rate-limiting scenario, we need to limit the number of login attempts for players and set an expiration time for that count. This allows us to restrict a player's login attempts within a specific time frame. Previously, we accomplished this using SCRIPT LOAD and EVALSHA (because we need to incr count and set expiration atomically.)
This makes us wonder: Why doesn't Redis offer a dedicated INCREX command for this? It seems like this is a very common requirement across many different business use cases.
Description of the feature
A new command INCREX
which incr a key and set expiration for it atomically.
command reference:
127.0.0.1:6379> increx nonexistent 100
(integer) 1
127.0.0.1:6379> ttl nonexistent
(integer) 99
127.0.0.1:6379> get nonexistent
"1"
127.0.0.1:6379> increx nonexistent 100
(integer) 2
127.0.0.1:6379> increx nonexistent 100
(integer) 3
127.0.0.1:6379> ttl nonexistent
(integer) 99
127.0.0.1:6379> get nonexistent
"3"
Alternatives you've considered
Currently we use script load
+ evalsha
to do the same thing. If a dedicated INCREX command can be provided, it will be of great help in daily operation and maintenance.
Additional information
Comment From: raffertyyu
@sundb please have a review.
Comment From: sundb
@raffertyyu IMHO, If lua can support it without being complicated and without performance issues, I actually prefer not to add new commands to support it.