Collection Commands
5 methods对列表、哈希、集合和有序集合进行操作的命令。
SET key value [EX seconds | PX ms] [NX | XX] [KEEPTTL]将一个或多个值推入列表的头部(LPUSH)或尾部(RPUSH)。
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 key在 key 上设置一个或多个哈希字段,如需要则创建哈希。
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to read. |
Returns
string | nil
Example
redis
GET session:42INCR key | INCRBY key 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 value以给定浮点分数添加或更新有序集合中的成员。
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]按索引、分数或字典序返回有序集合的成员范围。
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | Key to expire. |
| seconds | integer | TTL in seconds. |
Returns
0 | 1
Example
redis
EXPIRE session:42 3600