How to install redis max memory?

I find configure in this , it just said that the command uses the configure command:

./redis-server <path>/redis.conf 

But I have no idea how to write configure. So I found the default configuration in this . But I still do not understand how to set the maximum memory. Does it just add this line to configure?

 maxmemory 2mb 

By the way, I want to know how much the default memory costs. and I want to set the memory to 2 GB, how to do it?

Then I added this line to redis configure to set maxmemory to 40GB:

 maxmemory 41943040 

And I use the command in redis-cli:

 config get maxmemory 

this will show me:

 127.0.0.1:6379> config get maxmemory 1) "maxmemory" 2) "41943040" 

But, my java program throws an exception similar to this when the key number is around 200000:

 Exception in thread "Thread-228" redis.clients.jedis.exceptions.JedisDataException: OOM command not allowed when used memory > 'maxmemory'. at redis.clients.jedis.Protocol.processError(Protocol.java:117) at redis.clients.jedis.Protocol.process(Protocol.java:151) at redis.clients.jedis.Protocol.read(Protocol.java:205) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297) at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196) at redis.clients.jedis.Jedis.hmset(Jedis.java:644) at cn.ict.dt2redis.analyser.AbstractAnalyser.pushOne(AbstractAnalyser.java:21) at cn.ict.dt2redis.analyser.BatchAbstractAnalyser.run(BatchAbstractAnalyser.java:16) at java.lang.Thread.run(Thread.java:722) 

I have no idea if I managed to set the maximum memory to 40 GB? How to do it? please give me the code in detail.

+24
redis
source share
4 answers

Yes - to set the memory limit, just uncomment the maxmemory line in the .conf file. By default, 0, which means unlimited (until the operating system runs out of RAM and kills the process - I recommend always setting maxmemory to normal).

Updated: as @Eric Uldall mentioned in the comments, CONFIG SET maxmemory <sane value> followed by CONFIG REWRITE should also work. This will change your redis.conf to save changes in case of a restart

+27
source share

The documentation in the comments causes bytes, but I used extensions like mb & no problem.

 $ grep ^maxmemory /etc/redis-server.conf maxmemory 8gb maxmemory-policy allkeys-lru 

And to confirm:

 $ redis-cli ... 127.0.0.1:6379> config get maxmemory 1) "maxmemory" 2) "8589934592" 
+6
source share

maxmemory 41943040

set in bytes so you install 40 MB

+2
source share

If someone is still having problems configuring maxmemory in the local environment, the valid steps are as follows:

  1. In the terminal, run your instance of Redis redis-server
  2. In a new terminal window, run redis-cli
  3. In a new terminal window (step 2) run config set maxmemory 2mb
  4. Verify maxmemory by running config get maxmemory in the same terminal window as steps 2/3

Several are documented here in the Redis Configuration Changes section while the server is running .

0
source share

All Articles