一、排序
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"