Is it possible to create a script for Redis that flush its memory when it is above a certain value?
In my specific case, I want a flush when the memory is above 90%.
What is the best way, via bash script or Lua script?
Is it possible to create a script for Redis that flush its memory when it is above a certain value?
In my specific case, I want a flush when the memory is above 90%.
What is the best way, via bash script or Lua script?
2
Answers
That's the way to obtain the allocated memory
redis-cli -h 1.2.3.4 -p 6379 memory stats | sed -n 4p
. Now it's easy to create a bash scriptI would use a Lua script as it will perform faster, atomically, and it would be easy to use both from redis-cli and any application code.
Here a Lua script to get memory used and
maxmemory
, the percent, and an action placeholder. It uses bothMEMORY STATS
andINFO memory
to illustrate.MEMORY STATS
brings structured information, but doesn’t includemaxmemory
ortotal_system_memory
, asINFO memory
does.CONFIG GET
is not allowed from Lua scripts.Use as: