使用redis-cli 分析大key

数据库NoSQL数据库技术服务知识库
场景介绍

导致 redis 性能问题的因素有很多,大 key 是比较常见的因素,如果未能及时发现和处理,可能导致服务性能下降,用户体验变差。

分析大 key 的方法有很多,本文专注于如何使用原生 redis-cli 工具,通过添加 --bigkeys选项,可以快找出业务中的大 key

前提条件
  • ECS中已经安装了 Redis 4.0 以上版本;目的是为了使用 redis-cli 工具。
  • 保证客户端与 redis 网络互通。
操作步骤

运行如下命令,可以在整个实例级别来发现大 key:

(base) [root@rudonx ~]# redis-cli -h xxxxxx.redis.ivolces.com  -a xxxx --bigkeys
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# 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).
-------- summary -------
Sampled 0 keys in the keyspace!
Total key length in bytes is 0 (avg len 0.00)

0 hashs with 0 fields (00.00% of keys, avg size 0.00)
0 lists with 0 items (00.00% of keys, avg size 0.00)
0 strings with 0 bytes (00.00% of keys, avg size 0.00)
0 streams with 0 entries (00.00% of keys, avg size 0.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
(base) [root@rudonx ~]# redis-cli -h redis-cnlffe3qya6r6fuga.redis.ivolces.com  -a ASDFasdf@2020 --bigkeys
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

# 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 string found so far '"{application_list:123456}"' with 4 bytes
[00.00%] Biggest string found so far '"key:{tag}:001151754414"' with 20 bytes
[00.60%] Biggest list   found so far '"mylist:{tag}"' with 39256600 items
[00.83%] Biggest hash   found so far '"myhash:{tag}:000000000164"' with 200 fields
[06.79%] Sampled 1000000 keys so far
[13.57%] Sampled 2000000 keys so far
[20.36%] Sampled 3000000 keys so far
[27.14%] Sampled 4000000 keys so far
[33.93%] Sampled 5000000 keys so far
[40.71%] Sampled 6000000 keys so far
[47.50%] Sampled 7000000 keys so far
[54.28%] Sampled 8000000 keys so far
[60.40%] Biggest set    found so far '"myset:{tag}"' with 200 members
[61.07%] Sampled 9000000 keys so far
[67.85%] Sampled 10000000 keys so far
[74.64%] Sampled 11000000 keys so far
[81.42%] Sampled 12000000 keys so far
[88.21%] Sampled 13000000 keys so far
[94.99%] Sampled 14000000 keys so far

-------- summary -------
Sampled 14737769 keys in the keyspace!
Total key length in bytes is 343177455 (avg len 23.29)

Biggest   list found '"mylist:{tag}"' has 39256600 items
Biggest   hash found '"myhash:{tag}:000000000164"' has 200 fields
Biggest string found '"key:{tag}:001151754414"' has 20 bytes
Biggest    set found '"myset:{tag}"' has 200 members

1 lists with 39256600 items (00.00% of keys, avg size 39256600.00)
203 hashs with 40008 fields (00.00% of keys, avg size 197.08)
14737564 strings with 204599828 bytes (100.00% of keys, avg size 13.88)
0 streams with 0 entries (00.00% of keys, avg size 0.00)
1 sets with 200 members (00.00% of keys, avg size 200.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)

参数解释

  • -h:Redis 实例的地址。
  • -a:指定 Redis 实例的密码。
  • --bigkeys:进行大 key 分析
参考文档

[1] https://redis.io/docs/ui/cli/

47
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论