127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> set name 測(cè)試
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 #設(shè)置過期時(shí)間
(integer) 1
127.0.0.1:6379> setex name3 10 ceshi3 #set值并設(shè)置過期時(shí)間
OK
127.0.0.1:6379> ttl name1 #查看過期時(shí)間
(integer) -2
127.0.0.1:6379> setnx name4 ceshi4 #set值,該值如果存在返回0,不會(huì)覆蓋原值
(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"
它是鏈表,不是數(shù)組,插入和刪除操作很快,時(shí)間復(fù)雜度O(1),查找很慢
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),廣德企業(yè)網(wǎng)站建設(shè),廣德品牌網(wǎng)站建設(shè),網(wǎng)站定制,廣德網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,廣德網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
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 #添加多個(gè)
(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"
存儲(chǔ)中獎(jiǎng)用戶列表,有去重功能
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 #根據(jù)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