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

memjs

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memjs - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

69

lib/memjs/memjs.js

@@ -86,2 +86,11 @@ // # MemJS Memcache Client

// converts a call into a promise-returning one
var promisify = function(command) {
return new Promise(function(resolve, reject) {
command(function(err, result) {
err ? reject(err) : resolve(result);
});
});
};
// ## Memcache Commands

@@ -113,5 +122,9 @@ //

Client.prototype.get = function(key, callback) {
if(typeof callback === undefined) {
if(callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.get(key, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) {
self.get(key, function(err, value, flags) {
callback(err, {value: value, flags: flags});
});
});
}

@@ -153,5 +166,5 @@ var logger = this.options.logger;

Client.prototype.set = function(key, value, options, callback) {
if(typeof callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.set(key, value, options, function(err, val) { err ? reject(err) : resolve(val); }); });
if(callback === undefined && typeof options !== 'function') {
var self = this;
return promisify(function(callback) { self.set(key, value, options, function(err, success) { callback(err, success); }); });
}

@@ -206,5 +219,5 @@ var logger = this.options.logger;

Client.prototype.add = function(key, value, options, callback) {
if(typeof callback === undefined) {
if(callback === undefined && options !== 'function') {
var self = this;
return new Promise(function(resolve, reject) { self.add(key, value, options, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.add(key, value, options, function(err, success) { callback(err, success); }); });
}

@@ -262,5 +275,5 @@ var logger = this.options.logger;

Client.prototype.replace = function(key, value, options, callback) {
if(typeof callback === undefined) {
if(callback === undefined && options !== 'function') {
var self = this;
return new Promise(function(resolve, reject) { self.replace(key, value, options, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.replace(key, value, options, function(err, success) { callback(err, success); }); });
}

@@ -314,5 +327,5 @@ var logger = this.options.logger;

Client.prototype.delete = function(key, callback) {
if(typeof callback === undefined) {
if(callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.delete(key, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.delete(key, function(err, success) { callback(err, success); }); });
}

@@ -356,5 +369,9 @@ // TODO: Support version (CAS)

Client.prototype.increment = function(key, amount, options, callback) {
if(typeof callback === undefined) {
if(callback === undefined && options !== 'function') {
var self = this;
return new Promise(function(resolve, reject) { self.increment(key, amount, options, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) {
self.increment(key, amount, options, function(err, success, value) {
callback(err, {success: success, value: value});
});
});
}

@@ -414,5 +431,9 @@ var logger = this.options.logger;

Client.prototype.decrement = function(key, amount, options, callback) {
if(typeof callback === undefined) {
if(callback === undefined && options !== 'function') {
var self = this;
return new Promise(function(resolve, reject) { self.decrement(key, amount, options, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) {
self.decrement(key, amount, options, function(err, success, value) {
callback(err, {success: success, value: value});
});
});
}

@@ -468,5 +489,5 @@ // TODO: support version (CAS)

Client.prototype.append = function(key, value, callback) {
if(typeof callback === undefined) {
if(callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.append(key, value, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.append(key, value, function(err, success) { callback(err, success); }); });
}

@@ -505,5 +526,5 @@ // TODO: support version (CAS)

Client.prototype.prepend = function(key, value, callback) {
if(typeof callback === undefined) {
if(callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.prepend(key, value, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.prepend(key, value, function(err, success) { callback(err, success); }); });
}

@@ -542,5 +563,5 @@ // TODO: support version (CAS)

Client.prototype.touch = function(key, expires, callback) {
if(typeof callback === undefined) {
if(callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.touch(key, expires, function(err, val) { err ? reject(err) : resolve(val); }); });
return promisify(function(callback) { self.touch(key, expires, function(err, success) { callback(err, success); }); });
}

@@ -582,5 +603,5 @@ // TODO: support version (CAS)

Client.prototype.flush = function(callback) {
if(typeof callback === undefined) {
var self = this;
return new Promise(function(resolve, reject) { self.flush(function(err, val) { err ? reject(err) : resolve(val); }); });
if(callback === undefined) {
var self = this;
return promisify(function(callback) { self.flush(function(err, results) { callback(err, results); }); });
}

@@ -587,0 +608,0 @@ // TODO: support expiration

@@ -5,3 +5,3 @@ {

"description": "A memcache client for node using the binary protocol and SASL authentication",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "http://github.com/alevy/memjs",

@@ -8,0 +8,0 @@ "repository": {

@@ -72,2 +72,4 @@ MemJS

If callbacks are not specified, the command calls return promises.
### Settings Values

@@ -74,0 +76,0 @@

@@ -18,3 +18,3 @@ var test = require('tap').test;

var client = new MemJS.Client([dummyServer]);
client.get('hello', function(err, val, flags) {
var assertor = function(err, val, flags) {
t.equal('world', val);

@@ -24,3 +24,7 @@ t.equal('flagshere', flags);

t.equal(1, n, 'Ensure get is called');
t.end();
};
client.get('hello', assertor);
n = 0;
return client.get('hello').then(function(res) {
assertor(null, res.value, res.flags);
});

@@ -41,3 +45,3 @@ });

var client = new MemJS.Client([dummyServer]);
client.get('hello', function(val, flags) {
var assertor = function(val, flags) {
t.equal(null, val);

@@ -47,2 +51,7 @@ t.equal(null, flags);

t.end();
};
client.get('hello', assertor);
n = 0;
return client.get('hello').then(function(res) {
assertor(null, res.value, res.extras);
});

@@ -63,7 +72,11 @@ });

var client = new MemJS.Client([dummyServer]);
client.set('hello', 'world', {}, function(err, val) {
var assertor = function(err, val) {
t.equal(true, val);
t.equal(null, err);
t.equal(1, n, 'Ensure set is called');
t.end();
};
client.set('hello', 'world', {}, assertor);
n = 0;
return client.set('hello', 'world', {}).then(function (success){
assertor(null, success);
});

@@ -125,7 +138,11 @@ });

var client = new MemJS.Client([dummyServer]);
client.set('hello', 'world', {}, function(err, val) {
var assertor = function(err, val) {
t.equal(null, val);
t.equal('MemJS SET: ' + errors[3], err.message);
t.equal(1, n, 'Ensure set is called');
t.end();
};
client.set('hello', 'world', {}, assertor);
n = 0;
return client.set('hello', 'world', {}).catch(function(err) {
assertor(err, null);
});

@@ -254,7 +271,11 @@ });

var client = new MemJS.Client([dummyServer], {expires: 1024});
client.add('hello', 'world', {}, function(err, val) {
var assertor = function(err, val) {
t.equal(null, err);
t.equal(true, val);
t.equal(1, n, 'Ensure add is called');
t.end();
};
client.add('hello', 'world', {}, assertor);
n = 0;
return client.add('hello', 'world', {}).then(function(success) {
assertor(null, success);
});

@@ -317,7 +338,11 @@ });

var client = new MemJS.Client([dummyServer], {expires: 1024});
client.replace('hello', 'world', {}, function(err, val) {
var assertor = function(err, val) {
t.equal(null, err);
t.equal(true, val);
t.equal(1, n, 'Ensure replace is called');
t.end();
};
client.replace('hello', 'world', {}, assertor);
n = 0;
return client.replace('hello', 'world', {}).then(function(success){
assertor(null, success);
});

@@ -378,7 +403,11 @@ });

var client = new MemJS.Client([dummyServer]);
client.delete('hello', function(err, val) {
var assertor = function(err, val) {
t.equal(null, err);
t.equal(true, val);
t.equal(1, n, 'Ensure delete is called');
t.end();
};
client.delete('hello', assertor);
n = 0;
return client.delete('hello').then(function(success) {
assertor(null, success);
});

@@ -419,7 +448,11 @@ });

var client = new MemJS.Client([dummyServer, dummyServer]);
client.flush(function(err, results) {
var assertor = function(err, results) {
t.equal(null, err);
t.equal(true, results['example.com:1234']);
t.equal(2, n, 'Ensure flush is called for each server');
t.end();
};
client.flush(assertor);
n = 0;
return client.flush().then(function(results) {
assertor(null, results);
});

@@ -426,0 +459,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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