I am writing a python script which will periodically check redis memory usage. Now I know that used_memory or used_memory_human from redis info will tell us how much memory redis is using currently. But I want to know how much percentage of memory has been utilised.
In redis info we don’t get something like max_memory because of the fact that redis uses up as much memory available to the system. But what if maxmemory option in the redis.conf was set?
What if my system has 1 GB of RAM but maxmemory was set to 100MB? How can we know the memory utilisation then?
You can use
CONFIGcommand to get needed info about maximum memory and memory policy. The syntax of getting configuration info is:Here’s an example of how you can get maxmemory setting:
Here’s and example of how you can get maxmemory-policy setting:
There’are different policies of maxmemory management (you can get their description from sample Redis config file):
And here’s and example of how similar result can be achieved with pyredis (assuming that we have localhost database on standard port):