GET
Retrieves the value at the given key in memcache.
The callback signature is:
callback(err, value, flags)
value and flags are both Buffer
s. If the key is not found, the
callback is invoked with null for both arguments and no error.
Client.prototype.get = function(key, callback) {
var self = this;
if(callback === undefined) {
return promisify(function(callback) {
self.get(key, function(err, value, flags) {
callback(err, {value: value, flags: flags});
});
});
}
var logger = this.options.logger;
this.incrSeq();
var request = makeRequestBuffer(0, key, '', '', this.seq);
this.perform(key, request, this.seq, function(err, response) {
if (err) {
if (callback) { callback(err, null, null); }
return;
}
switch (response.header.status) {
case 0:
if (callback) {
var deserialized = self.serializer.deserialize(response.header.opcode, response.val, response.extras);
callback(null, deserialized.value, deserialized.extras);
}
break;
case 1:
if (callback) { callback(null, null, null); }
break;
default:
var errorMessage = 'MemJS GET: ' + errors[response.header.status];
logger.log(errorMessage);
if (callback) { callback(new Error(errorMessage), null, null); }
}
});
};