问题
我的一个 Python Redis 客户端因以下异常而失败:
redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
我查过redis机器,好像内存不足:
免费
total used free shared buffers cached
Mem: 3952 3656 295 0 1 9
-/+ buffers/cache: 3645 306
Swap: 0 0 0
顶部
top - 15:35:03 up 14:09, 1 user, load average: 0.06, 0.17, 0.16
Tasks: 114 total, 2 running, 112 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.2 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.2 st
KiB Mem: 4046852 total, 3746772 used, 300080 free, 1668 buffers
KiB Swap: 0 total, 0 used, 0 free. 11364 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1102 root 20 0 3678836 3.485g 736 S 1.3 90.3 10:12.53 redis-server
1332 ubuntu 20 0 41196 3096 972 S 0.0 0.1 0:00.12 zsh
676 root 20 0 10216 2292 0 S 0.0 0.1 0:00.03 dhclient
850 syslog 20 0 255836 2288 124 S 0.0 0.1 0:00.39 rsyslogd
我在单个 Redis 实例中使用几十个 Redis 数据库。每个数据库都由提供给 redis-cli
的数字 ID 表示,例如:
$ redis-cli -n 80
127.0.0.1:6379[80]>
我如何知道每个数据库消耗多少内存,以及每个数据库中最大的键是什么?
最佳答案
How do I know how much memory does each DB consume, and what are the largest keys in each DB?
您无法获取每个数据库的已用内存。使用INFO
命令,您只能获取Redis 实例的全部使用内存。 Redis记录新分配的内存大小,每次动态分配一些内存。但是,它不会为每个数据库做这样的记录。此外,它没有任何最大键的记录。
通常,您应该使用 maxmemory
和 maxmemory-policy
配置您的 Redis 实例(即达到最大内存时的逐出策略)。
关于memory - 查找每个redis DB的内存消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39921402/