title: Storing nested javascript objects in redis - NodeJS
body: <p>I recently switched from memcached to redis in nodejs. The thing I liked in node-memcached was that I can save the whole javascript object in the memory. Sadly I couldn't do this in redis. For example, I got the following object:</p>
  
  <pre><code>var obj = {
      name: "Hello world!",
      author: "admin",
      user: {
          "yolololo" : {
               "id": "352asdsafaseww",
               "server": 5,
               "data" : {
                    x: 1, 
                    y: 1,
                    z: 50
               }
          },
          "yolol" : {
               "id": "358dsa",
               "server": 7
          }
      }
  }
  </code></pre>
  
  <p>with the <a href="https://github.com/3rd-Eden/node-memcached" rel="noreferrer">3rd-Eden/node-memcached</a> I could just do:</p>
  
  <pre><code>memcached.set("obj", obj, 12345, function(err) { });
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>memcached.get("obj", function(err, data) {
      console.log(data);
  });
  </code></pre>
  
  <p>And I'll get the object I saved, just the way it is.</p>
  
  <p>The problem with redis is that if I save the object like this:</p>
  
  <pre><code>redisclient.set("obj", obj, redis.print);
  </code></pre>
  
  <p>When I get the value with </p>
  
  <pre><code>redisclient.get("obj", function(err, data) {
      console.log(data);
  });
  </code></pre>
  
  <p>The output is just string containing <code>[object Object]</code>. </p>
  
  <p>Yeah I understand redis is text-based protocol and it's trying to do obj.toString(), but seems memcached take care of objects and redis don't.
  I thought I could just do:</p>
  
  <pre><code>redisClient.set("obj", JSON.stringify(obj));
  </code></pre>
  
  <p>but I'm not sure if this will be good, because there will be insane high I/O and I'm not sure if the JSON obj->string will be bottleneck ( 10k+ request/second ).</p>
  
  <p>Both Memcached and Redis store the data as string, but does redis have built-in feature for converting objects?</p>