ads:
关注以下公众号查看更多文章
慢查询日志
为了查找慢查询语句,先定义一下什么是慢查询
config set slowlog-log-slower-than 1000
定义了超过1ms 为慢查询
设置保存多少条慢查询记录语句
config set slowlog-max-len 999
取出两条慢查询日志
slowlog get 2
返回内容如下
1) 1) (integer) 29
2) (integer) 1669639983
3) (integer) 1030
4) 1) "INFO"
2) "all"
5) "127.0.0.1:52443"
6) ""
2) 1) (integer) 28
2) (integer) 1669639978
3) (integer) 1033
4) 1) "INFO"
2) "all"
5) "127.0.0.1:52443"
6) ""
1030、1033 是消耗的微秒数
设置latency容忍的最大毫秒数
config set latency-monitor-threshold 1000
查看最新记录的latency日志
latency latest
返回
127.0.0.1:6379> latency latest
1) 1) "command"
2) (integer) 1669640440
3) (integer) 2
4) (integer) 2
查找大key
redis-cli --bigkeys -i 0.1
返回内容如下
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest set found so far '"hset2"' with 5 members
[00.00%] Biggest string found so far '"scanf"' with 4 bytes
[00.00%] Biggest string found so far '"uid:sign:20200803"' with 376 bytes
[00.00%] Biggest zset found so far '"zset2"' with 4 members
[37.04%] Biggest hash found so far '"hscan2"' with 7 fields
[37.04%] Biggest stream found so far '"mq_new"' with 13 entries
-------- summary -------
Sampled 27 keys in the keyspace!
Total key length in bytes is 200 (avg len 7.41)
Biggest hash found '"hscan2"' has 7 fields
Biggest string found '"uid:sign:20200803"' has 376 bytes
Biggest stream found '"mq_new"' has 13 entries
Biggest set found '"hset2"' has 5 members
Biggest zset found '"zset2"' has 4 members
0 lists with 0 items (00.00% of keys, avg size 0.00)
1 hashs with 7 fields (03.70% of keys, avg size 7.00)
18 strings with 1221 bytes (66.67% of keys, avg size 67.83)
1 streams with 13 entries (03.70% of keys, avg size 13.00)
6 sets with 19 members (22.22% of keys, avg size 3.17)
1 zsets with 4 members (03.70% of keys, avg size 4.00)
从这份报告中可以看到每种数据类型占用字节最大的key
进一步的,我们想要知道这个key占用的内存大小,使用命令
memory usage hscan2
返回占用168字节