Created
October 13, 2011 18:52
-
-
Save erickdavidson/1285129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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