title: HSET vs SET memory usage?
body: <p>I was reading <a href="http://instagram-engineering.tumblr.com/post/12202313862/storing-hundreds-of-millions-of-simple-key-value-pairs" rel="noreferrer">this article</a> which mentions storing 1Million keys in redis will use 17GB of memory. However when switching to hashes chunking them at 1k each (ex: <code>HSET "mediabucket:1155" "1155315" "939"</code>) allows them to store 1M in 5GB which is a pretty large savings.</p>
  
  <p>I read <a href="http://redis.io/topics/memory-optimization" rel="noreferrer">redis memory-optimization</a> but I don't quite understand the difference. It says HGETs are not quite O(1) but close enough and mentions more cpu usage when using hsets. I don't understand why there would be more cpu usage (sure trading time for space. But how/what?). It mentions 'encoding' but not how they encode it.</p>
  
  <p>It also mentions only string but I have no idea what only string means. Is it the hash field? Does it mean the hash field? I don't see anything about it in <a href="http://redis.io/commands/hset" rel="noreferrer">HSET</a>. What exactly would be encoded and why would the encoding be more efficient then using a SET?</p>
  
  <p>How is it possible <code>HSET "mediabucket:1155" "1155315" "939"</code> is more efficient then <code>SET "mediabucket:1155315" "939"</code>? There less data in SET (1155315 an d 1155 is used rather then 1155315). I personally would try using binary keys however I don't think that has to do with why HSETs are more efficient.</p>
  
  <p>EDIT :</p>
  
  <p>Cross posted on redis-db mailing list as well : <a href="https://groups.google.com/d/topic/redis-db/90K3UqciAx0/discussion" rel="noreferrer">https://groups.google.com/d/topic/redis-db/90K3UqciAx0/discussion</a></p>