monitor是什么?
有時候我們需要知道客戶端對redis服務端做了那些命令操作丰介。我們可以試用monitor命令來查看。
他能清楚的看到客戶端在什么時間點執(zhí)行了那些命令
MONITOR 是一個調試命令扔罪,每個命令流回來的redis服務器處理娇掏。它可以幫助理解數據庫中正在發(fā)生的事情。此命令可用于通過使用CLI通過telnet空执±思看到所有的請求,由服務器處理為了點時使用Redis作為數據庫和分布式緩存系統(tǒng)的一個應用程序錯誤的能力是非常有用的
效果如下
1507515946.410170 [0 10.10.8.20:56169] "AUTH" "123456"
1507515946.426931 [0 10.10.8.20:56169] "PING"
1507515946.458043 [0 10.10.8.20:56169] "INFO" "ALL"
1507515946.477740 [0 10.10.8.20:56169] "select" "1"
1507515946.485924 [1 10.10.8.20:56169] "select" "2"
1507515946.519736 [2 10.10.8.20:56169] "select" "3"
1507515946.536863 [3 10.10.8.20:56169] "select" "4"
1507515946.539574 [4 10.10.8.20:56169] "select" "5"
1507515946.556423 [5 10.10.8.20:56169] "select" "6"
1507515946.583890 [6 10.10.8.20:56169] "select" "7"
1507515946.618607 [7 10.10.8.20:56169] "select" "8"
1507515946.632856 [8 10.10.8.20:56169] "select" "9"
1507515946.635165 [9 10.10.8.20:56169] "select" "10"
1507515946.656267 [10 10.10.8.20:56169] "select" "11"
1507515946.683463 [11 10.10.8.20:56169] "select" "12"
1507515946.702956 [12 10.10.8.20:56169] "select" "13"
1507515946.721350 [13 10.10.8.20:56169] "select" "14"
1507515946.735145 [14 10.10.8.20:56169] "select" "15"
1507515946.751276 [15 10.10.8.20:56169] "select" "16"
1507515947.879896 [15 10.10.8.20:56169] "SELECT" "0"
1507515947.928903 [0 10.10.8.20:56171] "AUTH" "123456"
1507515947.930488 [0 10.10.8.20:56171] "PING"
1507515947.949174 [0 10.10.8.20:56171] "INFO" "ALL"
1507515948.362843 [0 10.10.8.20:56156] "PING"
1507515948.466909 [0 10.10.8.20:56169] "scan" "0" "MATCH" "*" "COUNT" "10000"
1507515949.498885 [0 10.10.8.20:56169] "type" "2"
1507515949.501959 [0 10.10.8.20:56169] "ttl" "2"
1507515949.528084 [0 10.10.8.20:56169] "SCARD" "2"
1507515950.300299 [0 10.10.8.20:56169] "type" "xxx"
1507515950.302353 [0 10.10.8.20:56169] "ttl" "xxx"
1507515950.891284 [0 10.10.8.20:56169] "GET" "xxx"
1507515952.951806 [0 10.10.8.20:56171] "INFO" "all"
1507515954.605228 [0 10.10.8.20:56169] "type" "2"
1507515954.612624 [0 10.10.8.20:56169] "ttl" "2"
1507515954.616165 [0 10.10.8.20:56169] "SCARD" "2"
1507515954.789474 [0 10.10.8.20:56169] "SSCAN"
步驟
1辨绊、連接客戶端
./redis-cli
2奶栖、輸入密碼
auth xxxxx #xxxxx 表示密碼
3、輸入monitor命令
monitor
全部命令如下
[root@localhost src]# ./redis-cli
127.0.0.1:6379> monitor
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> monitor
OK
4邢羔、客戶端連接
可以直接在 redis-cli里輸入命令,也可以是其他的客戶端桑孩,monitor都可以監(jiān)控到拜鹤。這里用java為例
項目使用的是spring-boot, 源碼可以到我的github或者碼云中獲取流椒。
jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
yml文件
spring:
redis:
database: 0
host: 10.10.20.100
port: 6379
password: 123456
pool:
max-active: 8
max-wait: -1
max-idle: 18
min-idle: 0
timeout: 0
java文件
@Controller
@RequestMapping(value = "/test1")
public class SysTestController {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@ResponseBody
@GetMapping(value = "/redisTest")
public void redisTest(){
stringRedisTemplate.opsForValue().set("xxx","dddd");
stringRedisTemplate.opsForSet().add("2","x","c");
}
}
5敏簿、請求接口
http://localhost:8081/test1/redisTest
監(jiān)控臺可以看到
1507515925.616458 [0 10.10.8.20:56156] "AUTH" "123456"
1507515925.751292 [0 10.10.8.20:56156] "SET" "xxx" "dddd"
1507515925.914660 [0 10.10.8.20:56156] "SADD" "2" "x" "c"
6、注意
redis需要設置密碼和bind綁定的ip,在配置文件redis.conf中
點擊獲取優(yōu)惠券
點我獲取阿里云優(yōu)惠券
我的官網
我的博客
我的官網http://guan2ye.com
我的CSDN地址http://blog.csdn.net/chenjianandiyi
我的簡書地址http://www.reibang.com/u/9b5d1921ce34
我的githubhttps://github.com/javanan
我的碼云地址https://gitee.com/jamen/
阿里云優(yōu)惠券https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=vf2b5zld&utm_source=vf2b5zld
阿里云教程系列網站http://aliyun.guan2ye.com
1.png
我的開源項目spring boot 搭建的一個企業(yè)級快速開發(fā)腳手架
1.jpg