Skip to content

Instantly share code, notes, and snippets.

@erickdavidson
Created October 13, 2011 18:51
Show Gist options
  • Save erickdavidson/1285126 to your computer and use it in GitHub Desktop.
Save erickdavidson/1285126 to your computer and use it in GitHub Desktop.
if (Buffer.isBuffer(value)){
- flag = FLAG_BINARY;
+ if (compress) {
+ flag = FLAG_COMPRESSED;
+ value = new Buffer(zlib.deflate(value), 'binary');
+ } else {
+ flag = FLAG_BINARY;
+ }
+ length = value.length;
value = value.toString('binary');
} else if (valuetype !== 'string' && valuetype !== 'number'){
flag = FLAG_JSON;
value = JSON.stringify(value);
+ length = Buffer.byteLength(value);
} else {
value = value.toString();
+ length = Buffer.byteLength(value);
}
length = Buffer.byteLength(value);
if (length > memcached.maxValue) return private.errorResponse('The length of the value is greater than ' + memcached.maxValue, callback);
- memcached.command(function settersCommand(noreply){ return {
+ var lineBreakValue = new Buffer((new Buffer(value, 'binary')).length + 2);
+ lineBreakValue.write(LINEBREAK, 0, 'binary');
+ lineBreakValue.write(value, 2, 'binary');
+
+ memcached.command(function settersCommand(noreply){
+
+ var commandBuffer = new Buffer([type, key, flag, lifetime, length].join(' ') + (cas ? ' ' + cas : '') + (noreply ? NOREPLY : ''), 'binary');
+ var commandWithValue = new Buffer(commandBuffer.length + lineBreakValue.length);
+ commandBuffer.copy(commandWithValue, 0, 0);
+ lineBreakValue.copy(commandWithValue, commandBuffer.length, 0);
+
+ return {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment