Redis常用命令

#设置值
127.0.0.1:6379> set a1 1
OK
#键对应的值
127.0.0.1:6379> get a1
"1"
#删除键对应的值
127.0.0.1:6379> DEL a1
(integer) 1
127.0.0.1:6379> get a1
(nil)
#哈希
127.0.0.1:6379> HMSET h1 f1 v1 f2 v2 #同时将多个field - value(域-值)对设置到哈希表key中
OK
127.0.0.1:6379> HGETALL h1
1) "f1"
2) "v1"
3) "f2"
4) "v2"


127.0.0.1:6379> HSET h1 f3 3 #将多一个field - value(域-值)对设置到哈希表key中
(integer) 1
127.0.0.1:6379> HGETALL h1
1) "f1"
2) "v1"
3) "f2"
4) "v2"
5) "f3"
6) "3"

#增加 1
127.0.0.1:6379> HINCRBY  h1 f3 1 #value 必须为数字
(integer) 4
127.0.0.1:6379> HGETALL h1
1) "f1"
2) "v1"
3) "f2"
4) "v2"
5) "f3"
6) "4"
#减少1
127.0.0.1:6379> HINCRBY  h1 f3 -1
(integer) 3
127.0.0.1:6379> HGETALL h1
1) "f1"
2) "v1"
3) "f2"
4) "v2"
5) "f3"
6) "3"
#列表
127.0.0.1:6379> LPUSH a3 test1 #列表左边添加
(integer) 1
127.0.0.1:6379> LPUSH a3 test2
(integer) 2
127.0.0.1:6379> RPUSH a3 test3 #列表右边添加
(integer) 3
127.0.0.1:6379> LRANGE a3 0 -1
1) "test2"
2) "test1"
3) "test3"
#分页,每页3条记录
127.0.0.1:6379> LRANGE a3 0 -1
1) "test2"
2) "test1"
3) "test3"
4) "test4"
5) "test5"
6) "test6"
7) "test7"
8) "test8"
9) "test9"
#第一页:LRANGE a3 0 2
#第二页:LRANGE a3 3 5

#排序 ALPHA安字母排序
127.0.0.1:6379> SORT a3 ALPHA 
1) "test1"
2) "test2"
3) "test3"
4) "test4"
5) "test5"
6) "test6"
7) "test7"
8) "test8"
9) "test9"
127.0.0.1:6379> SORT a3 desc  ALPHA 
1) "test9"
2) "test8"
3) "test7"
4) "test6"
5) "test5"
6) "test4"
7) "test3"
8) "test2"
9) "test1"
#带分页排序
127.0.0.1:6379> SORT a3 desc  ALPHA limit 0 3
1) "test9"
2) "test8"
3) "test7"
#有序集合
127.0.0.1:6379> ZADD a4 1 test1
(integer) 1
127.0.0.1:6379> ZADD a4 2 test2
(integer) 1
127.0.0.1:6379> ZADD a4 3 test3
(integer) 1
127.0.0.1:6379> ZADD a4 4 test4
(integer) 1
127.0.0.1:6379> ZRANGE a4 0 -1
1) "test1"
2) "test2"
3) "test3"
4) "test4"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值