Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the maximum memory size that Redis can use?

Tags:

redis

nosql

To be specific, I only have 1GB of free memory and would like to use only 300MB for Redis. How can I configure it so that it is only uses up to 300MB of memory?

Out of curiosity, what happen when you try to insert a new data and Redis is already used all the memory allocated?

like image 589
Cory Avatar asked Mar 02 '11 00:03

Cory


People also ask

How much memory will Redis use?

An empty instance uses ~ 3MB of memory. 1 Million small Keys -> String Value pairs use ~ 85MB of memory. 1 Million Keys -> Hash value, representing an object with 5 fields, use ~ 160 MB of memory.

Does Redis have a max size?

All string values are limited to 512 MiB. This is the size limit you probably care most about. EDIT: Because keys in Redis are strings, the maximum key size is 512 MiB. The maximum number of keys is 2^32 - 1 = 4,294,967,295.


1 Answers

maxmemory is the correct configuration option to prevent Redis from using too much RAM.

If an insert causes maxmemory to be exceeded, the insert operation will sometimes fail.

Redis will do everything in its power to prevent the operation from failing, though. In the newer versions of Redis, you can configure the memory reclaiming policies in the configuration, as well by setting the maxmemory-policy option.

Also, if you have virtual memory options turned on, Redis will begin to store stale data to the disk.

More info:

  • What does Redis do when it runs out of memory?
like image 63
BMiner Avatar answered Oct 02 '22 16:10

BMiner