Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

memcache-plus

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memcache-plus - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

14

lib/client.js

@@ -125,2 +125,3 @@ /**

var h = this.splitHost(host);
var client = this;

@@ -131,3 +132,6 @@ // Connect to host

port: h.port,
reconnect: this.reconnect
reconnect: this.reconnect,
onConnect: function() {
client.flushBuffer();
}
});

@@ -219,6 +223,6 @@ }, this);

assert.ok(keys, 'Cannot delete without keys!');
return Promise.all(R.map(function(key) {
return self.run('delete', [key], cb);
}, keys));
return Promise.props(R.reduce(function(acc, key) {
acc[key] = self.run('delete', [key], null);
return acc;
}, {}, keys)).nodeify(cb);
};

@@ -225,0 +229,0 @@

@@ -72,3 +72,3 @@ /**

debug("connecting to host %s:%s", params.host, params.port);
debug('connecting to host %s:%s', params.host, params.port);

@@ -133,3 +133,3 @@ // If a client already exists, we just want to reconnect

this.queue.shift();
deferred.reject(new Error('Memcache returned an error: ' + data.toString()));
deferred.reject(new Error(util.format('Memcache returned an error: %s\r\nFor key %s', data.toString(), deferred.key)));
this.data = null;

@@ -140,3 +140,3 @@ }

// Do nothing, this is just metadata. May want to somehow store this
// and send it back somehow in the future
// and send it back somehow in the future for debugging purposes
debug('Got some metadata');

@@ -147,3 +147,3 @@ } else if (data.toString().substr(0, 3) === 'END') {

this.data = null;
} else if (data.toString().substr(0, 6) === 'STORED' || data.toString().substr(0, 7) === 'DELETED') {
} else if (data.toString() === 'STORED' || data.toString() === 'DELETED' || data.toString() === 'EXISTS') {
this.queue.shift();

@@ -158,2 +158,7 @@ deferred.resolve(data);

this.data = data;
} else {
// If this is a response we do not recognize, what to do with it...
this.queue.shift();
deferred.reject(data);
this.data = null;
}

@@ -301,6 +306,12 @@ }

return deferred.promise
.then(function(v) {
if (v === 'DELETED') {
return true;
} else {
return false;
}
});
// .timeout() // @todo add this as a setting
.return(true);
};
module.exports = Connection;
{
"name": "memcache-plus",
"version": "0.1.1",
"version": "0.1.2",
"description": "Better memcache for node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,2 +10,16 @@ require('chai').should();

describe('Client', function() {
var keys = [];
// We want a method for generating keys which will store them so we can
// do cleanup later and not litter memcache with a bunch of garbage data
var getKey = function(opts) {
var key;
if (opts) {
key = chance.word(opts);
} else {
key = chance.guid();
}
keys.push(key);
return key;
};
describe('initialization', function() {

@@ -56,3 +70,2 @@ it('with defaults', function() {

* Ideally one day this can be mocked, but for now just selectively enabling it
*/
it('supports autodiscovery', function(done) {

@@ -71,3 +84,3 @@ var cache = new Client({ hosts: ['victor.di6cba.cfg.use1.cache.amazonaws.com'], autodiscover: true });

});
/**/
*/
});

@@ -77,2 +90,3 @@

var cache;
before(function() {

@@ -92,3 +106,3 @@ cache = new Client();

it('with a key that is too long', function() {
expect(function() { cache.set(chance.word({length: 251})); }).to.throw('less than 250 characters');
expect(function() { cache.set(chance.string({length: 251}), chance.word()); }).to.throw('less than 250 characters');
});

@@ -104,6 +118,7 @@

it('should work', function() {
var val = chance.word();
return cache.set('mykey', val)
var key = getKey(), val = chance.word();
return cache.set(key, val)
.then(function() {
return cache.get('mykey');
return cache.get(key);
})

@@ -116,7 +131,7 @@ .then(function(v) {

it('works with very large values', function() {
var val = chance.word({ length: 600000 });
var key = getKey(), val = chance.word({ length: 600000 });
return cache.set('mykey', val)
return cache.set(key, val)
.then(function() {
return cache.get('mykey');
return cache.get(key);
})

@@ -129,7 +144,8 @@ .then(function(v) {

it('works fine with special characters', function() {
var val = chance.string({ pool: 'ÀÈÌÒÙàèìòÁÉÍÓÚáéíóúÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüÿæ☃', length: 1000 });
var key = getKey(),
val = chance.string({ pool: 'ÀÈÌÒÙàèìòÁÉÍÓÚáéíóúÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüÿæ☃', length: 1000 });
return cache.set('mykey', val)
return cache.set(key, val)
.then(function() {
return cache.get('mykey');
return cache.get(key);
})

@@ -142,8 +158,9 @@ .then(function(v) {

it('works with callbacks as well', function(done) {
var val = chance.word();
cache.set('mykey', val, function(err) {
var key = getKey(), val = chance.word();
cache.set(key, val, function(err) {
if (err !== null) {
done(err);
}
cache.get('mykey', function(err, v) {
cache.get(key, function(err, v) {
if (err !== null) {

@@ -159,7 +176,8 @@ done(err);

it('multiple should not conflict', function() {
var val1 = chance.word(), val2 = chance.word(), val3 = chance.word();
var key1 = getKey(), key2 = getKey(), key3 = getKey(),
val1 = chance.word(), val2 = chance.word(), val3 = chance.word();
var item1 = cache.set('mykey1', val1)
var item1 = cache.set(key1, val1)
.then(function() {
return cache.get('mykey1');
return cache.get(key1);
})

@@ -170,5 +188,5 @@ .then(function(v) {

var item2 = cache.set('mykey2', val2)
var item2 = cache.set(key2, val2)
.then(function() {
return cache.get('mykey2');
return cache.get(key2);
})

@@ -179,5 +197,5 @@ .then(function(v) {

var item3 = cache.set('mykey3', val3)
var item3 = cache.set(key3, val3)
.then(function() {
return cache.get('mykey3');
return cache.get(key3);
})

@@ -191,2 +209,34 @@ .then(function(v) {

it('many multiple operations should not conflict', function() {
var key = getKey(), key1 = getKey(), key2 = getKey(), key3 = getKey(),
val1 = chance.word(), val2 = chance.word(), val3 = chance.word();
return cache.set(key, val1)
.then(function() {
return Promise.all([
cache.delete(key),
cache.set(key1, val1),
cache.set(key2, val2),
cache.set(key3, val3)
]);
})
.then(function() {
return Promise.all([cache.get(key1), cache.get(key2), cache.get(key3)]);
})
.then(function(v) {
v[0].should.equal(val1);
v[1].should.equal(val2);
v[2].should.equal(val3);
return Promise.all([
cache.get(key1),
cache.deleteMulti([key1, key3])
]);
})
.then(function(v) {
v[0].should.equal(val1);
});
});
describe('get to key that does not exist returns error', function() {

@@ -214,13 +264,13 @@ it('with Promise', function() {

it('works', function() {
var val1 = chance.word(),
val2 = chance.word();
var key1 = getKey(), key2 = getKey(),
val1 = chance.word(), val2 = chance.word();
return Promise.all([cache.set('val1', val1), cache.set('val2', val2)])
return Promise.all([cache.set(key1, val1), cache.set(key2, val2)])
.then(function() {
return cache.getMulti(['val1', 'val2']);
return cache.getMulti([key1, key2]);
})
.then(function(vals) {
vals.should.be.an('object');
vals['val1'].should.equal(val1);
vals['val2'].should.equal(val2);
vals[key1].should.equal(val1);
vals[key2].should.equal(val2);
});

@@ -230,6 +280,4 @@ });

it('get with array of keys delegates to getMulti', function() {
var key1 = chance.word(),
key2 = chance.word(),
val1 = chance.word(),
val2 = chance.word();
var key1 = getKey(), key2 = getKey(),
val1 = chance.word(), val2 = chance.word();

@@ -248,13 +296,12 @@ return Promise.all([cache.set(key1, val1), cache.set(key2, val2)])

it('works if some values not found', function() {
var key = chance.word(),
key2 = chance.word(),
var key1 = getKey(), key2 = getKey(),
val = chance.word();
return cache.set(key, val)
return cache.set(key1, val)
.then(function() {
return cache.getMulti([key, key2]);
return cache.getMulti([key1, key2]);
})
.then(function(vals) {
vals.should.be.an('object');
vals[key].should.equal(val);
vals[key1].should.equal(val);
expect(vals[key2]).to.equal(null);

@@ -265,5 +312,3 @@ });

it('works if all values not found', function() {
var key = chance.word(),
key2 = chance.word(),
key3 = chance.word(),
var key = getKey(), key2 = getKey(), key3 = getKey(),
val = chance.word();

@@ -284,5 +329,3 @@

it('works if all values not found with callback', function(done) {
var key = chance.word(),
key2 = chance.word(),
key3 = chance.word(),
var key = getKey(), key2 = getKey(), key3 = getKey(),
val = chance.word();

@@ -316,3 +359,3 @@

it('works', function() {
var key = chance.word();
var key = getKey();

@@ -332,3 +375,3 @@ return cache.set(key, 'myvalue')

it('does not blow up if deleting key that does not exist', function() {
var key = chance.word();
var key = chance.guid();

@@ -351,4 +394,3 @@ return cache.delete(key);

it('works', function() {
var key1 = chance.word(),
key2 = chance.word();
var key1 = getKey(), key2 = getKey();

@@ -359,11 +401,12 @@ return Promise.all([cache.set(key1, 'myvalue'), cache.set(key2, 'myvalue')])

})
.then(function() {
return cache.get(key1);
.then(function(d) {
d.should.be.an.object;
_.values(d).indexOf(null).should.equal(-1);
_.every(d).should.be.true;
return Promise.all([cache.get(key1), cache.get(key2)]);
})
.then(function(v) {
expect(v).to.be.null;
return cache.get(key2);
})
.then(function(v) {
expect(v).to.be.null;
.spread(function(v1, v2) {
expect(v1).to.be.null;
expect(v2).to.be.null;
return;
});

@@ -415,2 +458,10 @@ });

});
after(function() {
var cache = new Client();
// Clean up all of the keys we created
return cache.deleteMulti(keys);
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc