title: Memcache response: "bad command line format" on Google Cloud Platform with large values using node.js
body: <p>Modifying the example found <a href="https://cloud.google.com/appengine/docs/flexible/nodejs/caching-application-data" rel="nofollow">on the Google App Engine Documentation</a> to store a large string results in an response <code>Error: bad command line format</code></p>
  
  <p>Often subsequent requests will then be met with <code>Error: Server at &lt;IP&gt;:11211 not available</code> as if something in the set function briefly knocks the server offline.</p>
  
  <p>Tried running in GAE's shared Memcache as well as with a dedicated 1GB (10,000 MCU per second per GB) with no difference.</p>
  
  <p>Multiple nodejs memcached libraries as well as large Buffer and JSON formatted values all return the same error. All of my research appears to show that this error tends to come from a 'key' greater than 250 characters, but not from a large value (since attempt below is well short of both the Memcache quota and the 1MiB limit per value).</p>
  
  <p>Here's a full app.js to demonstrate:</p>
  
  <pre><code>'use strict';
  
  var express = require('express');
  var Memcached = require('memcached');
  
  var app = express();
  
  // The environment variables are automatically set by App Engine when running
  // on GAE. When running locally, you should have a local instance of the
  // memcached daemon running.
  var memcachedAddr = process.env.MEMCACHE_PORT_11211_TCP_ADDR || 'localhost';
  var memcachedPort = process.env.MEMCACHE_PORT_11211_TCP_PORT || '11211';
  var memcached = new Memcached(memcachedAddr + ':' + memcachedPort);
  
  app.get('/', function(req, res, next) {
    memcached.get('foo', function(err, value) {
      if (err) { return next(err); }
      if (value) {
          console.log('Exists');
        return res.status(200).send('Value: ' + value);
      }
  
  
      var str = "";
  
      // Make a big string
      var loops = 1000;
      // works with loops = 10, fails with loops = 1000
      for(var i = 0; i &lt; loops; i++){
          str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      }
  
      memcached.set('foo', str, 60, function(err) {
        if (err) { return next(err); }
        console.log('Created');
        return res.redirect('/');
      });
    });
  });
  
  var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() {
    console.log('App listening at http://%s:%s', server.address().address,
      server.address().port);
    console.log('Press Ctrl+C to quit.');
  });
  </code></pre>
  
  <p>The same large string can be manually set in Memcache using the Google Cloud Console form. Subsequent calls to retrieve the value also work. Am I drastically miscalculating MCU based on the value size? </p>
  
  <p>When running locally (OSX) I experience zero issues and am able to store very large values. Error only occurs with deployed code. Any advice or direction is much appreciated.</p>