Socket
Socket
Sign inDemoInstall

memcached

Package Overview
Dependencies
2
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.6 to 0.2.7

17

lib/memcached.js

@@ -378,2 +378,3 @@ "use strict";

, remove: this.remove
, failOverServers: this.failOverServers || null
});

@@ -846,3 +847,3 @@

(Array.isArray(results) ? results : [results]).forEach(function each(value) {
if (memcached.namespace.length) {
if (value && memcached.namespace.length) {
var ns_key = Object.keys(value)[0]

@@ -869,5 +870,7 @@ , newvalue = {};

callback: handle
, multi:true
, multi: true
, type: 'get'
, command: 'get ' + key.join(' ')
, key: keys
, validate: [['key', Array], ['callback', Function]]
};

@@ -1007,5 +1010,6 @@ }, server);

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

@@ -1020,3 +1024,3 @@ , value: value

, redundancyEnabled: true
, command: [type, key, value].join(' ') +
, command: [type, fullkey, value].join(' ') +
(noreply ? NOREPLY : '')

@@ -1033,5 +1037,6 @@ };

memcached.del = function del(key, callback){
var fullkey = this.namespace + key;
this.command(function deleteCommand(noreply) {
return {
key: key
key: fullkey
, callback: callback

@@ -1044,3 +1049,3 @@ , validate: [

, redundancyEnabled: true
, command: 'delete ' + key +
, command: 'delete ' + fullkey +
(noreply ? NOREPLY : '')

@@ -1047,0 +1052,0 @@ };

@@ -32,3 +32,13 @@ "use strict";

}
if (!err && key === 'key') {
for (var vKey in value) {
var vValue = value[vKey];
var result = validateKeySize(config, vKey, vValue);
if (result.err) {
err = result.err;
} else {
args.command = args.command.replace(vValue, result['value']);
}
}
}
break;

@@ -56,13 +66,7 @@

if (!err && key === 'key') {
if (value.length > config.maxKeySize) {
if (config.keyCompression){
args[key] = createHash('md5').update(value).digest('hex');
// also make sure you update the command
args.command = args.command.replace(value, args[key]);
} else {
err = 'Argument "' + key + '" is longer than the maximum allowed length of ' + config.maxKeySize;
}
} else if (/[\s\n\r]/.test(value)) {
err = 'The key should not contain any whitespace or new lines';
var result = validateKeySize(config, key, value);
if (result.err) {
err = result.err;
} else {
args.command = args.command.replace(value, result['value']);
}

@@ -80,3 +84,3 @@ }

if (err){
if(args.callback) args.callback(new Error(err));
if (args.callback) args.callback(new Error(err));
return false;

@@ -88,5 +92,19 @@ }

var validateKeySize = function validateKeySize(config, key, value) {
if (value.length > config.maxKeySize) {
if (config.keyCompression){
return { err: false, value: createHash('md5').update(value).digest('hex') };
} else {
return { err: 'Argument "' + key + '" is longer than the maximum allowed length of ' + config.maxKeySize };
}
} else if (/[\s\n\r]/.test(value)) {
return { err: 'The key should not contain any whitespace or new lines' };
} else {
return { err: false, value: value };
}
};
// a small util to use an object for eventEmitter
exports.fuse = function fuse (target, handlers) {
for(var i in handlers)
for (var i in handlers)
if (handlers.hasOwnProperty(i)){

@@ -93,0 +111,0 @@ target.on(i, handlers[i]);

{
"name": "memcached"
, "version": "0.2.6"
, "version": "0.2.7"
, "author": "Arnout Kazemier"

@@ -5,0 +5,0 @@ , "description": "A fully featured Memcached API client, supporting both single and clustered Memcached servers through consistent hashing and failover/failure. Memcached is rewrite of nMemcached, which will be deprecated in the near future."

@@ -216,3 +216,3 @@ # Memcached [![Build Status](https://secure.travis-ci.org/3rd-Eden/node-memcached.png?branch=master)](http://travis-ci.org/3rd-Eden/node-memcached)

Replaces the value in memcached.
Replaces the value in memcached.

@@ -234,3 +234,3 @@ **Arguments**

Add the value, only if it's in memcached already.
Add the value, only if it's not in memcached already.

@@ -237,0 +237,0 @@ **Arguments**

@@ -607,2 +607,23 @@ /**

});
/*
Make sure that getMulti calls work for very long keys.
If the keys aren't hashed because they are too long, memcached will throw exceptions, so we need to make sure that exceptions aren't thrown.
*/
it("make sure you can getMulti really long keys", function(done) {
var memcached = new Memcached(common.servers.single)
, message = 'My value is not relevant'
, testnr1 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"+(++global.testnumbers)
, testnr2 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"+(global.testnumbers)+"a"
, callbacks = 0;
memcached.getMulti([ testnr1, testnr2 ], function(error, ok) {
++callbacks;
assert.ok(!error);
memcached.end();
assert.equal(callbacks, 1);
done();
});
});
});

@@ -107,2 +107,131 @@ 'use strict';

});
/**
* In this case, these keys will be allocated to servers like below.
* test1,3,4 => :11211
* test5 => :11212
* test2 => :11213
*/
it('multi get from multi server with custom namespace (inc. cache miss)', function (done) {
var memcached = new Memcached(common.servers.multi, {
namespace: 'mySegmentedMemcached:'
})
, callbacks = 0;
// Load two namespaced variables into memcached
memcached.set('test1', 'test1answer', 1000, function (error, ok) {
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.set('test2', 'test2answer', 1000, function (error, ok) {
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.get(['test1', 'test2', 'test3', 'test4', 'test5'], function (error, answer) {
++callbacks;
assert.ok(typeof answer === 'object');
answer.test1.should.eql('test1answer');
answer.test2.should.eql('test2answer');
answer.should.not.have.key('test3');
answer.should.not.have.key('test4');
answer.should.not.have.key('test5');
memcached.end(); // close connections
assert.equal(callbacks, 3);
done();
});
});
});
});
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();
});
});
});
});
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc