SET
Syntax
Section titled “Syntax”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.
Examples
Section titled “Examples”localhost:7379> SET k 43OKlocalhost:7379> SET k 43 EX 10OKlocalhost:7379> SET k 43 PX 10000OKlocalhost:7379> SET k 43 EXAT 1772377267OKlocalhost:7379> SET k 43 PXAT 1772377267000OKlocalhost:7379> SET k 43 XXOKlocalhost:7379> SET k 43 NXOKlocalhost:7379> SET k 43 KEEPTTLOK