python - 找出 Redis 数据库中键的最大字符串值大小

标签 python redis

我需要查看我们的 Redis 缓存,看看我们最大存储值的大小是多少。我有 Python 经验或可以直接使用 redis-cli。有没有办法迭代数据库中的所有键,以便我可以检查每个值的大小?

看起来 SCAN 是遍历键的方法,但我仍在研究如何使用它来获取值的大小并存储最大值。

最佳答案

既然你提到了 redis-cli 作为一个选项,它有一个 build it 函数,几乎可以完成你所要求的(以及更多)。

redis-cli --bigkeys

# 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).

这里是一个总结输出的例子:

Sampled 343799 keys in the keyspace!
Total key length in bytes is 9556361 (avg len 27.80)

Biggest string found '530f8dc7c7b3b:39:string:87929' has 500 bytes
Biggest list found '530f8d5a17b26:9:list:11211' has 500 items
Biggest set found '530f8da856e1e:75:set:65939' has 500 members
Biggest hash found '530f8d619a0af:86:hash:16911' has 500 fields
Biggest zset found '530f8d4a9ce31:45:zset:315' has 500 members

68559 strings with 17136672 bytes (19.94% of keys, avg size 249.96)
68986 lists with 17326343 items (20.07% of keys, avg size 251.16)
68803 sets with 17236635 members (20.01% of keys, avg size 250.52)
68622 hashs with 17272144 fields (19.96% of keys, avg size 251.70)
68829 zsets with 17241902 members (20.02% of keys, avg size 250.50)

您可以查看完整的输出示例 here

关于python - 找出 Redis 数据库中键的最大字符串值大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26870303/

相关文章:

ruby-on-rails - Redis:在 httparty 客户端中正确缓存来自 API 的响应,根据 api 响应中的缓存 header 使缓存过期

redis - Redis server_load 统计数据的计量单位是什么?

python - 打包在 requirements.txt 中,但在 docker 中看不到

python - 使用子进程和 .Popen 自动执行 .exe 程序的简单 Windows 示例

python - Pandas 范围日期极度减慢功能

python - JSON或Python dict/list解码问题

javascript - 创建基本分析页面

perl - Dancer2::Plugin::Redis中 'retry'和 'every'配置参数的意义是什么

Python 数组缓存与 C 数组缓存

python - 在 Python 中全局处理对象的属性?