String Commands
5 methodsCommands operating on Redis string values.
SET key value [EX seconds | PX ms] [NX | XX] [KEEPTTL]Sets key to value with optional expiry and existence condition flags.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to set. |
| value | string | Value to store. |
| EX | integer | Expire in seconds. |
| NX | flag | Only set if key does not exist. |
| XX | flag | Only set if key already exists. |
Returns
OK | nil
Example
redis
SET session:42 abc123 EX 3600 NXGET keyReturns the string value stored at key, or nil if the key does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to read. |
Returns
string | nil
Example
redis
GET session:42INCR key | INCRBY key deltaAtomically increments the integer value stored at key by one or by the given delta.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key holding an integer string. |
| delta | integer | Increment for INCRBY; defaults to 1 for INCR. |
Returns
integer
Example
redis
INCR counter:pageviewsAPPEND key valueAppends value to the string at key, creating it if it does not exist. Returns the new length.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to append to. |
| value | string | Value to append. |
Returns
integer
Example
redis
APPEND log:today "newline\n"EXPIRE key seconds [NX | XX | GT | LT]Sets a time-to-live in seconds on a key, with optional condition flags.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to expire. |
| seconds | integer | TTL in seconds. |
Returns
0 | 1
Example
redis
EXPIRE session:42 3600