title: Optimal way to store array of integers in Redis database
body: <p>I am storing ~300M objects in a redis database. The object consist of :</p>
  
  <ul>
  <li>an ID</li>
  <li>a date</li>
  <li>an array of 48 values</li>
  </ul>
  
  <p>I use the ID/date as a key and I am looking for the optimal way (memory usage) of storing the 48 values.</p>
  
  <p>The value are integers and will usually be between [1-1000].</p>
  
  <p>The first way I used consisted in building in object in Java and use a framework (spring-data-redis) which automatically serializes the object.</p>
  
  <p>The resulting format is something like : </p>
  
  <blockquote>
    <p>{\"@class\":\"com.mycompany.Points\",\"faceId\":1234,\"date\":[\"java.util.Date\",1509663600000],\"points\":[5,5,10,10,10,10,60,60,60,60,60,60,40,40,40,40,40,40,30,30,30,30,30,80,80,80,80,80,80,80,20,20,20,20,20,10,10,10,10,10,5,5,5,5,5,5,5,5]}</p>
  </blockquote>
  
  <p>I then used this command to track the size of this object in redis : </p>
  
  <pre><code>redis 127.0.0.1:6379&gt; DEBUG OBJECT POINTS_215004#03-11-2017
  Value at:0x7fce4b2b6ac0 refcount:1 encoding:raw serializedlength:206 lru:2074768 lru_seconds_idle:10
  </code></pre>
  
  <p>So if I read it correctly, the entry takes <strong>206</strong> (206 what?) in the database.</p>
  
  <p>I tried to store it as a list : </p>
  
  <pre><code>redis 127.0.0.1:6379&gt; lpush dummy 1 2 3 4 5 [...] 48
  (integer) 48
  </code></pre>
  
  <p>And actually, the size was almost the same: </p>
  
  <pre><code>redis 127.0.0.1:6379&gt; DEBUG OBJECT dummy
  Value at:0x7fce467c2800 refcount:1 encoding:ziplist serializedlength:205 lru:2074809 lru_seconds_idle:10
  </code></pre>
  
  <p>Maybe the type <code>ziplist</code> is more memory consuming.</p>
  
  <p>Then I tried to store it as a plain string : </p>
  
  <pre><code>redis 127.0.0.1:6379&gt; set dummy  [5,5,10,10,10,10,60,60,60,60,60,60,40,40,40,40,40,40,30,30,30,30,30,80,80,80,80,80,80,80,20,20,20,20,20,10,10,10,10,10,5,5,5,5,5,5,5,5]
  </code></pre>
  
  <p>The size decreased to <strong>53</strong> :</p>
  
  <pre><code>redis 127.0.0.1:6379&gt; debug object dummy
  Value at:0x7fce470b2dc0 refcount:1 encoding:raw serializedlength:53 lru:2074818 lru_seconds_idle:10
  </code></pre>
  
  <p>It there a more apprioriate way to store this array?</p>