Skip to content

Redis String API

Redis 集合数据类型命令:列表、哈希、集合和有序集合。

1 class · 5 methods

Collection Commands

5 methods

对列表、哈希、集合和有序集合进行操作的命令。

SET key value [EX seconds | PX ms] [NX | XX] [KEEPTTL]

将一个或多个值推入列表的头部(LPUSH)或尾部(RPUSH)。

Parameters

NameTypeDescription
keystringKey to set.
valuestringValue to store.
EXintegerExpire in seconds.
NXflagOnly set if key does not exist.
XXflagOnly set if key already exists.

Returns

OK | nil

Example

redis
SET session:42 abc123 EX 3600 NX
GET key

在 key 上设置一个或多个哈希字段,如需要则创建哈希。

Parameters

NameTypeDescription
keystringKey to read.

Returns

string | nil

Example

redis
GET session:42
INCR key | INCRBY key delta

向集合添加一个或多个成员,忽略重复。返回新成员计数。

Parameters

NameTypeDescription
keystringKey holding an integer string.
deltaintegerIncrement for INCRBY; defaults to 1 for INCR.

Returns

integer

Example

redis
INCR counter:pageviews
APPEND key value

以给定浮点分数添加或更新有序集合中的成员。

Parameters

NameTypeDescription
keystringKey to append to.
valuestringValue to append.

Returns

integer

Example

redis
APPEND log:today "newline\n"
EXPIRE key seconds [NX | XX | GT | LT]

按索引、分数或字典序返回有序集合的成员范围。

Parameters

NameTypeDescription
keystringKey to expire.
secondsintegerTTL in seconds.

Returns

0 | 1

Example

redis
EXPIRE session:42 3600