Redis Multi-Set With a TTL

There is an issue for it back to 2012. For people who are wondering why they're not implement it.

Unfortunately, we're not going to add more commands that can work on multiple keys because they are inherently difficult to distribute. Instead, explicitly calling EXPIRE for every key you want to expire is much easier to distribute (you can route every command to a different server if needed). If you want to EXPIRE keys atomically, you can wrap multiple calls in a MULTI/EXEC block.


BTW, if the transaction is not required, try using pipeline instead of MULTI/EXEC for better performance.

Pipelining is not just a way to reduce the latency cost associated with the round trip time, it actually greatly improves the number of operations you can perform per second in a given Redis server.


I was also looking for this kind of operation. I didn't find anything, so I did it with MULTI/EXEC:

MULTI
expire key1
expire key2
expire key3
EXEC