|
|
|
@ -20,6 +20,7 @@ var kestrel = function( options ){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this._pendingSetCallback = null; |
|
|
|
|
|
|
|
ee2.call(this); |
|
|
|
} |
|
|
|
@ -75,7 +76,12 @@ function _handleData(data, self){ |
|
|
|
data = data.toString(); |
|
|
|
|
|
|
|
if( data.match('STORED\r\n') != null ){ |
|
|
|
self.emit('stored', true); |
|
|
|
self.emit('stored', true); |
|
|
|
if(self._pendingSetCallback){ |
|
|
|
var callback = self._pendingSetCallback; |
|
|
|
self._pendingSetCallback = null; |
|
|
|
callback(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if( data.match(/^VALUE/) != null ){ |
|
|
|
@ -189,17 +195,34 @@ kestrel.prototype.close = function(){ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
kestrel.prototype.set = function( queue, value, lifetime ){ |
|
|
|
kestrel.prototype.set = function( queue, value, lifetime, callback){ |
|
|
|
if( typeof(lifetime) === "function" ){ |
|
|
|
callback = lifetime; |
|
|
|
lifetime = null; |
|
|
|
} |
|
|
|
if( lifetime == undefined || lifetime == null ){ |
|
|
|
lifetime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if(this._pendingSetCallback && callback){ |
|
|
|
return callback("Cannot write again. Still waiting for previous write to be stored"); |
|
|
|
} |
|
|
|
|
|
|
|
var command = "SET " + queue + " 0 " + lifetime + " "; |
|
|
|
command += Buffer.byteLength(value, 'utf8') + "\r\n" + value + "\r\n"; |
|
|
|
|
|
|
|
var connection = this._getConnection(); |
|
|
|
if( connection != null ){ |
|
|
|
connection.write(command); |
|
|
|
if(callback){ |
|
|
|
this._pendingSetCallback = callback; |
|
|
|
} |
|
|
|
connection.write(command); |
|
|
|
} else { |
|
|
|
if(callback){ |
|
|
|
callback("No connection"); |
|
|
|
} else { |
|
|
|
throw new Error("No connection"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return this; |
|
|
|
|