Skip to content
This repository was archived by the owner on Feb 13, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion lib/memcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
*
* @author Tim Eggert <tim@elbart.com>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*
* MODIFIED BY:
* Richard Sylvester - FXRLabs
* June 2012
*
* Added correct "cas" functoinality"
* Added "gets" command to be used in conjunction with the "cas" command
* as having cas without gets is pointless.
*/

var tcp = require('net'),
Expand Down Expand Up @@ -121,6 +129,11 @@ Client.prototype.get = function(key, callback) {
return this.query('get ' + key, 'get', callback);
};

//RSS: Added June 7, 2012
Client.prototype.gets = function(key, callback)
{
return this.query('gets ' + key, 'gets', callback);
};

// all of these store ops (everything bu "cas") have the same format
Client.prototype.set = function(key, value, callback, lifetime, flags) { return this.store('set', key, value, callback, lifetime, flags); }
Expand Down Expand Up @@ -224,6 +237,17 @@ Client.prototype.handle_received_data = function(){
var next_result_at = result[1];
var result_error = result[2];

//RSS: Added June 7th, 2012
var resultFlags = null;
var resultCasUnique = null;

if(result.length >= 4)
resultFlags = result[3];

if(result.length >= 5)
resultCasUnique = result[4];
//END RSS

// does the current message need more data than we have?
// (this is how "get" ops ensure we've gotten all the data)
if (next_result_at > this.buffer.length){
Expand All @@ -235,7 +259,10 @@ Client.prototype.handle_received_data = function(){
var callback = this.callbacks.shift();
if (callback != null && callback.fun){
this.replies++;
callback.fun(result_error, result_value);
//RSS: Modified June 7th, 2012
//callback.fun(result_error, result_value);
callback.fun(result_error, result_value, resultFlags, resultCasUnique);
//END RSS
}
}
};
Expand Down Expand Up @@ -288,6 +315,44 @@ Client.prototype.handle_get = function(buffer) {
}
};

//RSS: Added June 7th, 2012
Client.prototype.handle_gets = function(buffer)
{
var next_result_at = 0;
var result_value = null;
var casUnique = null;
var flags = null;
var end_indicator_len = 3;
var result_len = 0;

if (buffer.indexOf('END') == 0)
{
return [result_value, end_indicator_len + crlf_len, null, flags, casUnique];
} else if (buffer.indexOf('VALUE') == 0 && buffer.indexOf('END') != -1)
{
first_line_len = buffer.indexOf(crlf) + crlf_len;
parts = buffer.substr(0,first_line_len - crlf_len).split(' ');
flags = parts[2];
casUnique = parts.length >= 5 ? parts[4] : null;

var end_indicator_start = buffer.indexOf('END');
result_len = end_indicator_start - first_line_len - crlf_len;
result_value = buffer.substr(first_line_len, result_len);

return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len, null, flags, casUnique];
} else {
var parts = buffer.substr(0,first_line_len - crlf_len).split(' ');
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var result_len = parts[3];
flags = parts[2];
casUnique = parts.length >= 5 ? parts[4] : null;
result_value = buffer.substr(first_line_len, result_len);

return [result_value, first_line_len + parseInt(result_len ) + crlf_len + end_indicator_len + crlf_len, null, flags, casUnique];
}
};
//END RSS

Client.prototype.handle_stats = function(buffer){

// special case - no stats at all
Expand Down