Redis
Start Server
-
Find redis server
where redis-server
-
Start Server
./redis-server &
keys
- 查看所有件
keys *
- 删除key
del [key]
String
-
insert String
set [key] [value]
-
get String
get [key]
-
Set expiration time
set [key] [value] EX [timeout/s] set [key] [timeout/s] [value]
-
Show expiration time
ttl [ket]
-
Rework expiration time
expire [key] [timeout/s]
-
Show all keys
keys *
list
- Add element to the left of the list
lpush [key] [value]
Insert the value into the header of the list 'key', if key does not exist, an empty list will be created and the
lpush
will be performed. When key exist but is not a list type, an error returned.
- Add element to the right of the list
rpush [key] [value]
Insert the value into the tail of the list 'key', if key does not exist, an empty list will be created and the
rpush
will be performed, When key exist but is not a list type, an error returned.
- Show element of the list
lrange [key] [start] [stop]
starting from 0 and ending with -1
-
Pop elements of the list
rpop [key]
andrpop [key]
-
Delete element of the list
lrem [key] [count] [value]
- count > 0: Start form the head to the end of the table, remove the elements equal to 'value', the number of 'count'.
- count < 0: Start from the end to the head of the table, remove the elements equal to 'value', the number if 'count'.
- count = 0, Remove all values equal to 'value' from the table.
-
Capped lists
ltrim [key] [start] [end]
-
Index element of the list
lindex [key] [index]
-
Get the number if elements in the list
llen [key]
Set
No duplicate objects
-
Add members of the Set
sadd [set] [value]
-
Show members of the Set
smembers [set]
-
Remove members of the Set
scrm set [member]
-
Show All members of the Set
scard set
-
Intersection
sinter [set1] [set2]
-
Union
sunion [set1] [set2]
-
Complement
sdiff [set1] [set2]
Sorted Set
-
insert
zadd [key] [num]
-
删除并返回排序集中得分最高的成员
zpopmax [key] [count]
-
删除并返回排序集中得分最低的成员
zpopmin [key] [count]
-
获取序列中的成员书
zcard [key]
-
在给定值内的分数中对排序集中的成员进行计数
zcount [key] [min] [max]
-
取出排序的几个
(
是包含zrangebyscore test (99 100 limit 0 100
Hash
- Add a new values
hset [key] [field] [value]
将哈希表 key 中的域 field 的值设为 value 如果 key 不存在,一个新的哈希表被创建并进行 HSET 操作。如果域 f1e1d 已经存在于哈希表中,旧值 将被覆盖。
-
获取哈希中的 field 对应的值
hget [key] [field]
-
删除 Field 中的某个 field:
hdel [key] [field]
-
获取某个哈希中所有的 field 和 value:
hgetall [key]
-
获取某个哈希中所有的 field:
hkeys [key]
-
获取某个哈希中所有的值:
hvals [key]
-
判断哈希中是否存在某个field:
hexists [key] [field]
-
获取哈希中总共的键值对:
hlen [field]