Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SET with EX option and SETEX in Redis?

Tags:

redis

While browsing Redis command reference, I came across two very similar comands:

  • SET with EX option: https://redis.io/commands/set
  • SETEX: https://redis.io/commands/setex

The SETEX boasts itself as an atomic way to do SET and EXPIRE, yet by the looks of it the same thing can be achieved with SET EX as it's also a single command.

SETEX was added in 2.0.0, while EX parameter was added in 2.6.12, so it seems that the former remains for the backwards compatibility, but for some reason it's not marked as deprecated.

Did I miss anything? Are there any valid cases for using SETEX nowadays?

like image 280
Nikolay Edigaryev Avatar asked Dec 31 '25 06:12

Nikolay Edigaryev


1 Answers

The SET documentation says:

Note: Since the SET command options can replace SETNX, SETEX, PSETEX, it is possible that in future versions of Redis these three commands will be deprecated and finally removed.

So it's safe to say that there's no reason to use SETEX if you have Redis version 2.6.12 or higher.

like image 100
Kevin Christopher Henry Avatar answered Jan 04 '26 10:01

Kevin Christopher Henry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!