title: How to decode/decompress values from memcached-backed Rails cache (Dalli gem) in Node.js
body: <p>I have a Rails application that is caching data in memcached via the Dalli gem (<a href="https://github.com/mperham/dalli" rel="noreferrer">https://github.com/mperham/dalli</a>).</p>
  
  <p>I would like to read the contents of this cache from Node.js. I am using the mc module to interface with memcached in Node.js.</p>
  
  <p>The problem I'm running into is with encoding and compression. Dalli uses <code>Zlib::Deflate.deflate(data)</code> (<a href="https://github.com/mperham/dalli/blob/master/lib/dalli/compressor.rb" rel="noreferrer">https://github.com/mperham/dalli/blob/master/lib/dalli/compressor.rb</a>). When I attempt to inflate from Node.js I get an error when trying to inflate with the zlib module:</p>
  
  <pre><code>{ [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR' }
  </code></pre>
  
  <p>Here is relevant Ruby/Rails code:</p>
  
  <pre><code>config.cache_store = :dalli_store, memcached_server, {compress: true}
  </code></pre>
  
  <p>And the relevant Node.js code:</p>
  
  <pre><code>client = new Memcached.Client(MEMCACHED_HOSTNAME, Memcached.Adapter.raw);
  
  
  client.get(key, function (err, response) {
    var data = response[key];
  
    zlib.inflate(data.buffer, function (err, buf) {
      console.log(err, buf);
    });
  });
  </code></pre>
  
  <p>The buffer the comes back from memcached's string value looks like this:</p>
  
  <p><code>'\u0004\b[\u0015i\u0006i\u0007i\bi\ti\ni\u000bi\fi\ri\u000ei\u000fi\u0010i\u0011i\u0012i\u0014i\u0015i\u0016'</code></p>
  
  <p>The value that I'm expecting after inflating is something like: <code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17]</code></p>