Feature rollout management for Node.js built on Redis
Example Usage
Installation
npm install node-rollout --save
Basic Configuration
// basic_configuration.jsvar client = require('redis').createClient()var rollout = require('node-rollout')(client)rollout.handler('new_homepage', { // 1% of regular users id: { percentage: 1 }, // All users with the company email employee: { percentage: 100, condition: function (val) { return /@company-email\.com$/.test(val) } }, // 50% of users in San Francisco geo_sf: { percentage: 50, condition
For clients that require a client factory or function that returns connections, the clientFactory can be given a
function that returns a client.
This can be useful when using ioredis with Cluster support.
Note: Functions like multi() may not work as expected with ioredis clusters.
modName: String The name of the modifier. Typically id, employee, ip, or any other arbitrary item you would want to modify the rollout
percentage:
Number from 0 - 100. Can be set to a third decimal place such as 0.001 or 99.999. Or simply 0 to turn off a feature, or 100 to give a feature to all users
Object containing min and max keys representing a range of Numbers between 0 - 100
condition: Function a white-listing method by which you can add users into a group. See examples.
if condition returns a Promise (a thenable object), then it will use the fulfillment of the Promise to resolve or reject the handler
Conditions will only be accepted if they return/resolve with a "truthy" value
rollout.handler('admin_section', { // 0% of regular users. You may omit `id` since it will default to 0 id: { percentage: 0 }, // All users with the company email employee: { percentage: 100, condition: function (val) { return /@company-email\.com$/.test(val) } }, // special invited people contractors: { percentage: 100, condition: function (user) { return new Promise(function (resolve, reject) { redisClient.get('contractors:' + user.id, function
rollout.update(key, modifierPercentages)
key: String The rollout feature key
modifierPercentages: Object mapping of modName:String to percentage
Number from 0 - 100. Can be set to a third decimal place such as 0.001 or 99.999. Or simply 0 to turn off a feature, or 100 to give a feature to all users
Object containing min and max keys representing a range of Numbers between 0 - 100
returns Promise
rollout.update('new_homepage', { id: 33.333, employee: 50, geo_sf: 25}).then(function () { // values have been updated})
rollout.modifiers(handlerName)
handlerName: String the rollout feature key
returns Promise: resolves to a modifiers Object mapping modName: percentage
Consider using rollout-ui to administrate the values of your rollouts in real-time (as opposed to doing a full deploy). It will make your life much easier and you'll be happy :)
Note:rollout-ui does not yet support experiment groups and percentage ranges.