Robert C. Holland
Robert C. Holland

Reputation: 1813

How to initiate, increment and set expiration in the same Redis command?

INCR mykey initiates to 0 and increments the value to 1. How would I set expiration time to the mykey in the same command like it can be done with SETEX ?

Upvotes: 2

Views: 3017

Answers (1)

Tuan Anh Tran
Tuan Anh Tran

Reputation: 7267

you can use pipeline or a lua script

in fact, in redis documentation, there is an example of implementing rate limit that needs to increase and set ttl using multi

https://redis.io/commands/INCR

Upvotes: 6

Related Questions