node-rollout
Advanced tools
Comparing version 0.2.1 to 0.3.0
15
index.js
@@ -52,3 +52,13 @@ var crypto = require('crypto') | ||
Rollout.prototype.get = function (key, id, opt_values) { | ||
Rollout.prototype.multi = function (keys) { | ||
var multi = this.client.multi() | ||
var self = this | ||
var settler = when.settle(keys.map(function (k) { | ||
return self.get(k[0], k[1], k[2], multi) | ||
})) | ||
multi.exec(function () {}) | ||
return settler | ||
} | ||
Rollout.prototype.get = function (key, id, opt_values, multi) { | ||
var flags = this._handlers[key] | ||
@@ -65,3 +75,4 @@ var likely = this.val_to_percent(key + id) | ||
}) | ||
this.client.mget(keys, function (err, percentages) { | ||
var client = multi || this.client | ||
client.mget(keys, function (err, percentages) { | ||
var i = 0 | ||
@@ -68,0 +79,0 @@ var deferreds = [] |
{ | ||
"name": "node-rollout", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "feature rollout management", | ||
@@ -5,0 +5,0 @@ "author": "Dustin Diaz", |
@@ -90,2 +90,33 @@ ## Node Rollout | ||
#### `rollout.multi(keys)` | ||
The value of this method lets you do a batch redis call (using `redis.multi()`) allowing you to get multiple flags in one request | ||
- `keys`: `Array` A list of tuples containing what you would ordinarily pass to `get` | ||
- returns `SettlePromise` | ||
``` js | ||
rollout.multi([ | ||
['onboarding', 123, {}], | ||
['email_inviter', 123, {}], | ||
['facebook_chat', 123, { | ||
employees: req.user.email // 'joe@company.com' | ||
}] | ||
]) | ||
.then(function (results) { | ||
results.forEach(function (r) { | ||
console.log(i.state) // 'fulfilled' || 'rejected' | ||
}) | ||
}) | ||
rollout.get('another_feature', 123, { | ||
employee: 'user@example.org' | ||
}) | ||
.then(function () { | ||
render('blue_button') | ||
}) | ||
.otherwise(function () { | ||
render('red_button') | ||
}) | ||
``` | ||
#### `rollout.handler(key, flags)` | ||
@@ -112,8 +143,8 @@ - `key`: `String` The rollout feature key | ||
}, | ||
// active beta testers... | ||
betaTesters: { | ||
// special invited people | ||
contractors: { | ||
percentage: 100, | ||
condition: function (user) { | ||
return new Promise(function (resolve, reject) { | ||
redisClient.get('betagroup:' + user.id, function (err, is_awesome) { | ||
redisClient.get('contractors:' + user.id, function (err, is_awesome) { | ||
is_awesome ? resolve() : reject() | ||
@@ -120,0 +151,0 @@ }) |
16243
351
200