memcache-plus
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -12,3 +12,4 @@ /** | ||
Promise = require('bluebird'), | ||
Queue = require('collections/deque'); | ||
Queue = require('collections/deque'), | ||
R = require('ramda'); | ||
@@ -41,2 +42,3 @@ var Connection = require('./connection'); | ||
hosts: null, | ||
types: false, | ||
reconnect: true | ||
@@ -229,4 +231,4 @@ }); | ||
* | ||
* @param {String} key - The key to set | ||
* @param {Function} [cb] - The value to set for this key. Can be of any type | ||
* @param {String} key - The key to get | ||
* @param {Function} [cb] - The (optional) callback called on completion | ||
* @returns {Promise} | ||
@@ -236,4 +238,23 @@ */ | ||
assert.ok(key, 'Cannot get without key!'); | ||
if (_.isArray(key)) { | ||
return this.getMulti(key, cb); | ||
} else { | ||
return this.run('get', [key], cb); | ||
} | ||
}; | ||
return this.run('get', [key], cb); | ||
/** | ||
* getMulti() - Get multiple values for the provided array of keys | ||
* | ||
* @param {Array} keys - The keys to get | ||
* @param {Function} [cb] - The value to set for this key. Can be of any type | ||
* @returns {Promise} | ||
*/ | ||
Client.prototype.getMulti = function(keys, cb) { | ||
var self = this; | ||
assert.ok(keys, 'Cannot get without key!'); | ||
return Promise.all(R.map(function(key) { | ||
return self.run('get', [key], cb); | ||
}, keys)); | ||
}; | ||
@@ -240,0 +261,0 @@ |
{ | ||
"name": "memcache-plus", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Better memcache for node", | ||
@@ -45,4 +45,5 @@ "main": "index.js", | ||
"hashring": "^2.0.1", | ||
"lodash": "^2.4.1" | ||
"lodash": "^2.4.1", | ||
"ramda": "^0.2.3" | ||
} | ||
} |
@@ -174,2 +174,38 @@ require('chai').should(); | ||
}); | ||
describe('getMulti', function() { | ||
it('exists', function() { | ||
cache.should.have.property('getMulti'); | ||
}); | ||
it('works', function() { | ||
var val1 = chance.word(), | ||
val2 = chance.word(); | ||
return Promise.all([cache.set('val1', val1), cache.set('val2', val2)]) | ||
.then(function() { | ||
return cache.getMulti(['val1', 'val2']); | ||
}) | ||
.then(function(vals) { | ||
vals.should.be.an('array'); | ||
vals[0].should.equal(val1); | ||
vals[1].should.equal(val2); | ||
}); | ||
}); | ||
it('get with array of keys delegates to getMulti', function() { | ||
var val1 = chance.word(), | ||
val2 = chance.word(); | ||
return Promise.all([cache.set('val1', val1), cache.set('val2', val2)]) | ||
.then(function() { | ||
return cache.get(['val1', 'val2']); | ||
}) | ||
.then(function(vals) { | ||
vals.should.be.an('array'); | ||
vals[0].should.equal(val1); | ||
vals[1].should.equal(val2); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -176,0 +212,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35097
850
7
+ Addedramda@^0.2.3
+ Addedramda@0.2.4(transitive)