Guide for Memory Allocation for Redis in CentOS | BaseZap
In the last guide, we showed how we can install Redis on CentOS. In case you have missed it then follow here.
Today we will show you how memory allocation on Redis is done in CentOS so that it can store the progress as per the work is done on it. Redis Server on 32-bit machines has 3GB memory allocated by default whereas, the 64-bit machine doesn’t have the limit on memory usage.
- Redis installed on Linux Machine with Root Permissions
- Internet Connection
There are 2 methods to allocate memory to Redis.
First is temporary or can be said it works till Redis Server is running, after reboot, the memory allocations will be stashed and it will change to default values.
Second is change the maxmemory flag in redis config which is a permanent solution for allocating memory to Redis even if Redis Server is killed or restarted on the machine.
- Run redis CLI on your machine
- After your CLI is started run this command to check what are your current values for memory.
config get maxmemory
On 32-bit Machine it will show
On 64-bit Machine it will show
- After checking you current maxmemory configs run this command to allot 100MB memory for redis.
config set maxmemory 100MB
- After setting the maxmemory flag again verify maxmemory config like done in Step 2 above.
- If above steps followed you can see that maxmemory is now set to 100MB
Note – Using above method is temporary and changes will be stashed if Redis Server is crashed or restarted.
- Log in as root on your machine
- Edit Redis config for your redis-server
Note – redis.conf filename might be different here as per the user machine and installation method.
- Now we need to add the following flag or in simple words, a line needs to be added for memory allocation of 100MB
- Press CTRL+O to save the changes and CTRL+X to exit nano editor.
- Restart redis-server
For CentOS 6 run
service redis restart
For CentOS 7 run
systemctl restart redis
Note – servicename might be different here as per the user machine and installation method.
- Open redis-cli on your machine with any user other than root and run following commands
>config get maxmemory
It should throw results as per below pic
I would like to add extra information to guide which is related to memory and that is LRU Cache that has been added recently in Redis versions. Please refer to the official website about LRU Cache here.