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.2.8 to 0.2.9

docs/disconnect.md

1

docs/README.md

@@ -7,3 +7,4 @@ * [Memcache Plus](../README.md)

* [Delete](delete.md)
* [Disconnect](disconnect.md)
* [Elasticache](elasticache.md)
* [Miscellaneous](misc.md)

39

lib/client.js

@@ -96,16 +96,39 @@ /**

*/
Client.prototype.disconnect = function() {
Client.prototype.disconnect = function(opts) {
debug('starting disconnection');
var connections;
var connectionKeys = R.keys(this.connections);
connectionKeys.map(function(ckey) {
if (typeof opts === 'string') {
// If single connection provided, array-ify it
connections = [opts];
} else if (typeof opts === 'undefined') {
// No connections specified so client wants to disconnect from all
connections = R.keys(this.connections);
} else if (_.isArray(opts)) {
connections = opts;
}
if (connections.length === R.keys(this.connections).length) {
// Fair to assume if client is requesting a full disconnect, they don't
// want it to just reconnect
this.reconnect = false;
}
connections.map(function(ckey) {
debug('disconnecting from %s', ckey);
// Check that host exists before disconnecting from it
if (this.connections[ckey] === undefined) {
debug('failure trying to disconnect from server [%s] because not connected', ckey);
throw new Error('Cannot disconnect from server unless connected');
}
this.connections[ckey].disconnect();
// Remove this connection
delete this.connections[ckey];
// Remove this host from the list of hosts
this.hosts = this.hosts.filter(function(host) {
return host !== ckey;
});
}.bind(this));
this.connections = {};
// Fair to assume if client is requesting a disconnect, they don't want
// it to just reconnect
this.reconnect = false;
return Promise.resolve(null);

@@ -112,0 +135,0 @@ };

{
"name": "memcache-plus",
"version": "0.2.8",
"version": "0.2.9",
"description": "Better memcache for node",

@@ -11,3 +11,3 @@ "main": "index.js",

"type": "git",
"url": "git://github.com/socialradar/memcache-plus"
"url": "git://github.com/victorquinn/memcache-plus"
},

@@ -25,5 +25,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/socialradar/memcache-plus/issues"
"url": "https://github.com/victorquinn/memcache-plus/issues"
},
"homepage": "https://github.com/socialradar/memcache-plus",
"homepage": "https://github.com/victorquinn/memcache-plus",
"devDependencies": {

@@ -30,0 +30,0 @@ "chance": "^1.0.4",

@@ -57,2 +57,37 @@ require('chai').should();

it('can disconnect from a specific client with string', function(done) {
var cache = new Client({ hosts: ['localhost:11211', '127.0.0.1:11211'] });
cache.should.have.property('disconnect');
cache.disconnect.should.be.a('function');
cache.disconnect('127.0.0.1:11211')
.then(function() {
cache.connections.should.be.an('object');
_.keys(cache.connections).should.have.length(1);
cache.hosts.should.have.length(1);
_.keys(cache.connections)[0].should.equal('localhost:11211');
cache.hosts[0].should.equal('localhost:11211');
})
.then(done);
});
it('can disconnect from a specific client with array', function(done) {
var cache = new Client({ hosts: ['localhost:11211', '127.0.0.1:11211'] });
cache.should.have.property('disconnect');
cache.disconnect.should.be.a('function');
cache.disconnect(['127.0.0.1:11211'])
.then(function() {
cache.connections.should.be.an('object');
_.keys(cache.connections).should.have.length(1);
_.keys(cache.connections)[0].should.equal('localhost:11211');
})
.then(done);
});
it('throws an error if attempting to disconnect from a bogus host', function() {
var cache = new Client({ hosts: ['localhost:11211', '127.0.0.1:11211'] });
cache.should.have.property('disconnect');
cache.disconnect.should.be.a('function');
expect(function() { cache.disconnect(['badserver:11211']); }).to.throw('Cannot disconnect from server unless connected');
});
it('has a dictionary of connections', function() {

@@ -59,0 +94,0 @@ var cache = new Client();

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