Skip to content

SET

SET key value [EX seconds | PX milliseconds] [EXAT timestamp | PXAT timestamp] [XX | NX] [KEEPTTL]

SET puts or updates an existing value for a key.

SET stores the value as its native type - be it int or string. SET supports the following options:

  • EX seconds: set the expiration time in seconds
  • PX milliseconds: set the expiration time in milliseconds
  • EXAT timestamp: set the expiration time in seconds since epoch
  • PXAT timestamp: set the expiration time in milliseconds since epoch
  • XX: only set the key if it already exists
  • NX: only set the key if it does not already exist
  • KEEPTTL: keep the existing TTL of the key even if some expiration param like EX, etc is provided

Returns “OK” if the SET operation was successful.

localhost:7379> SET k 43
OK
localhost:7379> SET k 43 EX 10
OK
localhost:7379> SET k 43 PX 10000
OK
localhost:7379> SET k 43 EXAT 1772377267
OK
localhost:7379> SET k 43 PXAT 1772377267000
OK
localhost:7379> SET k 43 XX
OK
localhost:7379> SET k 43 NX
OK
localhost:7379> SET k 43 KEEPTTL
OK