Skip to main content
Version: 1.7.2

Simulating setting the memory limit of redis cache

Introduction

An experiment that simulates setting the memory limit of redis cache by modifying the maxmemory of redis.

Redis triggers the cache elimination policy to release the memory after the memory exceeds the specified maxmemory.

CLI Command

  • blade create redis cache-limit -h

Parameter

NameIntroductionTypeRequiredExample Value
addrThe address of redis server, the format is ip:port.stringY192.168.56.101:6379
passwordThe password of redis server.stringY123456
sizeThe size of maxmemory, default does not limit the memory size.The default value is 0.stringN256M
percentThe percentage of maxmemory.stringN50

Case

# set the maxmemory to 256M
# blade create redis cache-limit --addr 192.168.56.101:6379 --password 123456 --size 256M
{"code":200,"success":true,"result":"b6a0f477b7fb1f4c"}

# set the maxmemory to the 50% of the original value.
# blade create redis cache-limit --addr 192.168.56.101:6379 --password 123456 --percent 50
{"code":200,"success":true,"result":"b6a0f477b7fb1f4c"}

Principle

Modify the maxmemory by using Golang interface in go-redis package.

Q&A

Q: {"code":44000,"success":false,"error":"redis set origin max memory error: OOM command not allowed when used memory \u003e 'maxmemory'.: action not supported"}

A:The size parameter was illegal, and it needed to be a parameter similar to 256M.