您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。