title: How to set Redis max memory?
body: <p>I find the configure in <a href="http://redis.io/topics/config" rel="noreferrer">this</a>, it just said the command to use the specify configure:</p>
  
  <pre><code>./redis-server &lt;path&gt;/redis.conf
  </code></pre>
  
  <p>But,I have no idea about how to write the configure. So I have find the default configure in <a href="http://download.redis.io/redis-stable/redis.conf" rel="noreferrer">this</a>. But, I still don't understand how to set max memory. Does it just add this line in configure?</p>
  
  <pre><code>maxmemory 2mb
  </code></pre>
  
  <p>By the way, I want to know how much the default memory is. and I want to set the memory to 2GB, how to do it? </p>
  
  <p>Then, I have added this line to the redis configure to set maxmemory to 40GB:</p>
  
  <pre><code>maxmemory 41943040
  </code></pre>
  
  <p>And I use the command in redis-cli:</p>
  
  <pre><code>config get maxmemory
  </code></pre>
  
  <p>it show me:</p>
  
  <pre><code>127.0.0.1:6379&gt; config get maxmemory
  1) "maxmemory"
  2) "41943040"
  </code></pre>
  
  <p>But, my java program throw the exception like this when key number is about 200000:</p>
  
  <pre><code>Exception in thread "Thread-228" redis.clients.jedis.exceptions.JedisDataException: OOM command not allowed when used memory &gt; '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)
  </code></pre>
  
  <p>I have no idea about it, do I success in setting max memory to 40 GB? How to do it? please give me some code in detail.</p>