Commit ddedcf36 authored by Arnout Kazemier's avatar Arnout Kazemier

Merge pull request #179 from kevinludwig/master

add namespace for del, incrdecr commands, issue-111
parents 6ffa0b62 73ee6fb2
......@@ -1004,9 +1004,10 @@ Client.config = {
// Small handler for incr and decr's
privates.incrdecr = function incrdecr(type, key, value, callback) {
var fullkey = this.namespace + key;
this.command(function incredecrCommand(noreply) {
return {
key: key
key: fullkey
, callback: callback
, value: value
, validate: [
......@@ -1016,7 +1017,7 @@ Client.config = {
]
, type: type
, redundancyEnabled: true
, command: [type, key, value].join(' ') +
, command: [type, fullkey, value].join(' ') +
(noreply ? NOREPLY : '')
};
});
......@@ -1028,9 +1029,10 @@ Client.config = {
// Deletes the keys from the servers
memcached.del = function del(key, callback){
var fullkey = this.namespace + key;
this.command(function deleteCommand(noreply) {
return {
key: key
key: fullkey
, callback: callback
, validate: [
['key', String]
......@@ -1038,7 +1040,7 @@ Client.config = {
]
, type: 'delete'
, redundancyEnabled: true
, command: 'delete ' + key +
, command: 'delete ' + fullkey +
(noreply ? NOREPLY : '')
};
});
......
......@@ -147,4 +147,90 @@ describe('Memcached tests with Namespaces', function () {
});
});
});
it('should allow namespacing on delete', function(done) {
var memcached = new Memcached(common.servers.single, {
namespace:'someNamespace:'
}), callbacks = 0;
// put a value
memcached.set('test1', 'test1answer', 1000, function(error, ok) {
callbacks++;
assert.ok(!error);
ok.should.be.true;
// get it back
memcached.get('test1', function(error,answer) {
callbacks++;
assert.ok(typeof answer === 'string');
answer.should.eql('test1answer');
//delete it
memcached.del('test1', function(error) {
callbacks++;
assert.ok(!error);
// no longer there
memcached.get('test1', function(error,answer) {
callbacks++;
assert.ok(!error);
assert.ok(!answer);
memcached.end();
assert.equal(callbacks,4);
done();
});
});
});
});
});
it('should allow increment and decrement on namespaced values', function(done) {
var memcached = new Memcached(common.servers.single, {
namespace:'someNamespace:'
}), callbacks = 0;
// put a value
memcached.set('test1', 1, 1000, function(error, ok) {
callbacks++;
assert.ok(!error);
ok.should.be.true;
// increment it
memcached.incr('test1', 1, function(error) {
callbacks++;
assert.ok(!error);
// get it back
memcached.get('test1', function(error,answer) {
callbacks++;
assert.ok(!error);
assert.ok(typeof answer === 'number');
answer.should.be.eql(2);
// decrement it
memcached.decr('test1', 1, function(err) {
callbacks++;
assert.ok(!error);
// get it again
memcached.get('test1',function(error,answer) {
callbacks++;
assert.ok(!error);
assert.ok(typeof answer === 'number');
answer.should.be.eql(1);
//get rid of it
memcached.del('test1', function(error,answer) {
callbacks++;
assert.ok(!error);
memcached.end();
assert.equal(callbacks,6);
done();
});
});
});
});
});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment