一、排序
SORT <key> 對一個數字值的key進行排序
1、alpha 對字串型別的鍵進行排序
2、asc / desc
redis 預設升序排序asc
desc 與之相反
3、by
根據權重排序。
127.0.0.1:6379> sadd usres "vip" "ordinary" "visotor" (integer) 3 127.0.0.1:6379> sort usres alpha 1) "ordinary" 2) "vip" 3) "visotor" 127.0.0.1:6379> mset vip-sort 1 ordinary-sort 0 visotor-sort -1 OK 127.0.0.1:6379> sort usres by *-sort 1) "visotor" 2) "ordinary" 3) "vip" 127.0.0.1:6379>
4、limit <從哪開始><娶幾個>
127.0.0.1:6379> sort usres alpha limit 0 2 1) "ordinary" 2) "vip" 127.0.0.1:6379>
5、get
通過get模式匹配後格式化
127.0.0.1:6379> sort usres alpha 1) "ordinary" 2) "vip" 3) "visotor" 127.0.0.1:6379>
127.0.0.1:6379> set vip "sc" OK 127.0.0.1:6379> set ordinary "kk" OK 127.0.0.1:6379> set visotor "123ewdfrgv" OK 127.0.0.1:6379> sort usres alpha get * 1) "kk" 2) "sc" 3) "123ewdfrgv" 127.0.0.1:6379>
6、store 儲存排序結果
127.0.0.1:6379> sort usres alpha get * store names (integer) 3 127.0.0.1:6379> lrange names 0 -1 1) "kk" 2) "sc" 3) "123ewdfrgv" 127.0.0.1:6379>
7、上述選項執行順序
a、排序: alpha 、asc 、 desc 、 by
b、限制結果集:limit
c、獲取外部鍵:get
d、儲存排序結果:store
二、慢查詢日誌
設定超時毫秒數:slowlog-slower-than
127.0.0.1:6379> config set slowlog-slower-than 0
OK
設定最大記錄數量:slowlog-max-len
127.0.0.1:6379> config set slowlog-max-len 3 OK
檢視日誌 :slowlog get
127.0.0.1:6379> set sc "sun" OK 127.0.0.1:6379> set y "yuan" OK 127.0.0.1:6379> set c "ong" OK 127.0.0.1:6379> slowlog get 1) 1) (integer) 8 //日誌主鍵 2) (integer) 1520643052 //時間戳 3) (integer) 4 //時長 4) 1) "set" //命令以及引數 2) "c" 3) "ong" 5) "127.0.0.1:34010" 6) "" 2) 1) (integer) 7 2) (integer) 1520643032 3) (integer) 3 4) 1) "set" 2) "y" 3) "yuan" 5) "127.0.0.1:34010" 6) "" 3) 1) (integer) 6 2) (integer) 1520643024 3) (integer) 5 4) 1) "set" 2) "sc" 3) "sun" 5) "127.0.0.1:34010" 6) ""
三、監視器 monitor
監視器客戶端執行:
127.0.0.1:6379> monitor OK
請求客戶端,執行命令:
# redis-cli 127.0.0.1:6379> set name "sc" OK 127.0.0.1:6379>
監視器,監視:
127.0.0.1:6379> monitor OK 1520643372.474104 [0 127.0.0.1:34012] "COMMAND" 1520643389.095506 [0 127.0.0.1:34012] "set" "name" "sc"