如何找到分配给redis实例的内存?

问题描述 投票:3回答:2

使用Redis info命令,我可以获得redis服务器的所有统计信息。我也能够获得已用内存指标。

如何获取分配给Redis实例的总内存,以便获取使用的内存百分比?

redis
2个回答
3
投票

默认情况下,Redis会获得所有可用内存(尽可能多的内存以及所有可用的物理内存)。您可以使用maxmemory文件中的redis.conf参数限制分配给Redis的内存量。

这是文件的摘录:

# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory <bytes>

7
投票

你可以这样做:

$ ps aux -m | grep redis-server | head -n1 |  awk '{printf "VSZ: %dMB, RSS: %dMB\n", $5/1024, $6/1024}'

这将以MB为单位显示redis-server进程的舍入虚拟和实际内存大小(要查看实际数字,请从两个参数中删除/1024)。

© www.soinside.com 2019 - 2024. All rights reserved.