您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> set name 测试
OK
127.0.0.1:6379> get name
"\xe6\xb5\x8b\xe8\xaf\x95"
127.0.0.1:6379> exists name
(integer) 1
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> mset name1 ceshi1 name2 ceshi2 #批量set
OK
127.0.0.1:6379> mget name1 name2 #批量get
1) "ceshi1"
2) "ceshi2"
127.0.0.1:6379> expire name1 10 #设置过期时间
(integer) 1
127.0.0.1:6379> setex name3 10 ceshi3 #set值并设置过期时间
OK
127.0.0.1:6379> ttl name1 #查看过期时间
(integer) -2
127.0.0.1:6379> setnx name4 ceshi4 #set值,该值如果存在返回0,不会覆盖原值
(integer) 1
127.0.0.1:6379> setnx name4 ceshi4
(integer) 0
127.0.0.1:6379> incr age #+1
(integer) 11
127.0.0.1:6379> incrby age 10 #+n
(integer) 21
127.0.0.1:6379> incrby age 5
(integer) 26
127.0.0.1:6379> rpush yuyan java python php
(integer) 3
127.0.0.1:6379> llen yuyan #列表长度
(integer) 3
127.0.0.1:6379> lpop yuyan
"java"
127.0.0.1:6379> rpop yuyan
"php"
127.0.0.1:6379> lrange yuyan 0 1 #范围查找
1) "python"
它是链表,不是数组,插入和删除操作很快,时间复杂度O(1),查找很慢
127.0.0.1:6379> hset user_1 name xiaoli
(integer) 1
127.0.0.1:6379> hset user_1 age 12
(integer) 1
127.0.0.1:6379> hgetall user_1
1) "name"
2) "xiaoli"
3) "age"
4) "12"
127.0.0.1:6379> hget user_1 name
"xiaoli"
127.0.0.1:6379> hlen user_1
(integer) 2
127.0.0.1:6379> hmset user_2 name xiaowang age 13
OK
127.0.0.1:6379> hincrby user_2 age 2
(integer) 15
127.0.0.1:6379> sadd userid 3
(integer) 1
127.0.0.1:6379> sadd userid 3 4 5 6 #添加多个
(integer) 3
127.0.0.1:6379> smembers userid
1) "3"
2) "4"
3) "5"
4) "6"
127.0.0.1:6379> sismember userid 6 #是否包含
(integer) 1
127.0.0.1:6379> sismember userid 7
(integer) 0
127.0.0.1:6379> scard userid #长度
(integer) 4
127.0.0.1:6379> spop userid 2 #出
1) "5"
2) "3"
127.0.0.1:6379> smembers userid
1) "4"
2) "6"
存储中奖用户列表,有去重功能
127.0.0.1:6379> zadd ranklist 100 user_1 200 user_2 50 user_3 20 user_4
(integer) 4
127.0.0.1:6379> zcard ranklist #长度
(integer) 4
127.0.0.1:6379> zrange ranklist 0 -1 #按score正序排
1) "user_4"
2) "user_3"
3) "user_1"
4) "user_2"
127.0.0.1:6379> zrevrange ranklist 0 -1 #按score逆序排
1) "user_2"
2) "user_1"
3) "user_3"
4) "user_4"
127.0.0.1:6379> zscore ranklist user_4 #获取score值
"20"
127.0.0.1:6379> zscore ranklist user
(nil)
127.0.0.1:6379> zrangebyscore ranklist 20 30 #根据score值筛选
1) "user_4"
127.0.0.1:6379> zrangebyscore ranklist 40 inf withscores #inf无穷大,withscores返回score值
1) "user_3"
2) "50"
3) "user_1"
4) "100"
5) "user_2"
6) "200"
127.0.0.1:6379> zrem ranklist user_1 #删除
(integer) 1
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。