SET
Note
Official reference: SET.
Write a string, optionally conditional on whether the key exists.
Syntax
SET key value [NX | XX] [GET] [EX seconds | PX milliseconds | EXAT unix-seconds | PXAT unix-milliseconds | KEEPTTL]
NX creates only; XX overwrites only. GET returns the previous value. EX/PX specify seconds/milliseconds to live; EXAT/PXAT specify Unix timestamps. KEEPTTL retains expiration. Keep options in the order shown.
Expiration arguments support 64-bit integers, as literals or bound Java long values. PXAT accepts Unix millisecond timestamps directly.
Results
| Return | Rows | Content |
|---|---|---|
| Update count / Result set | --/1 | Value: When not using GET, returns 0 (not set) or 1 (set successfully) ResultSet: When using GET, VALUE field, STRING type |
Binding a byte[] key or value uses binary SET. With GET, VALUE is a byte[] and can be read with getBytes().
Example
SET demo:message hello EX 60
SET demo:message world XX GET KEEPTTL