Node Rollout
Feature rollout management for Node.js built on Redis
Example Usage
Installation
npm install node-rollout --save
Basic Configuration
// basic_configuration.jsvar client =var rollout = clientrolloutmoduleexports = rollout
// A typical Express app demonstrating rollout flags...var rollout =app{rollout}{res}
Experiment groups
// experiment_groups_configuration.jsvar client =var rollout = client// An experiment with 3 randomly-assigned groupsrolloutmoduleexports = rollout
// A typical Express app demonstrating experiment groups...var rollout =app{rollout}
Advanced Configuration
clientFactory
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.
// client_factory_configuration.jsvar Redis =var rollout ={returnport: 6380host: '127.0.0.1'port: 6381host: '127.0.0.1';}
Prefix option
An optional prefix can be passed to the constructor that prepends all keys used by the rollout library.
var client =var rollout = clientprefix: 'my_rollouts'
API Options
rollout.get(key, uid, opt_values)
key
:String
The rollout feature key. Eg "new_homepage"uid
:String
The identifier of which will determine likelyhood of falling in rollout. Typically a user id.opt_values
:Object
optional A lookup object with default percentages and conditions. Defaults to{id: args.uid}
- returns
Promise
rolloutrollout
rollout.multi(keys)
The value of this method lets you do a batch redis call (using redis.multi()
) allowing you to get multiple rollout handler results in one request
keys
:Array
A list of tuples containing what you would ordinarily pass toget
- returns
Promise
rolloutrollout
rollout.handler(key, modifiers)
key
:String
The rollout feature keymodifiers
:Object
modName
:String
The name of the modifier. Typicallyid
,employee
,ip
, or any other arbitrary item you would want to modify the rolloutpercentage
:Number
from0
-100
. Can be set to a third decimal place such as0.001
or99.999
. Or simply0
to turn off a feature, or100
to give a feature to all usersObject
containingmin
andmax
keys representing a range ofNumber
s between0
-100
condition
:Function
a white-listing method by which you can add users into a group. See examples.- if
condition
returns aPromise
(a thenable object), then it will use the fulfillment of thePromise
to resolve or reject thehandler
- Conditions will only be accepted if they return/resolve with a "truthy" value
- if
rollout
rollout.update(key, modifierPercentages)
key
:String
The rollout feature keymodifierPercentages
:Object
mapping ofmodName
:String
topercentage
Number
from0
-100
. Can be set to a third decimal place such as0.001
or99.999
. Or simply0
to turn off a feature, or100
to give a feature to all usersObject
containingmin
andmax
keys representing a range ofNumber
s between0
-100
- returns
Promise
rollout
rollout.modifiers(handlerName)
handlerName
:String
the rollout feature key- returns
Promise
: resolves to a modifiersObject
mappingmodName
:percentage
rollout
rollout.handlers()
- return
Promise
: resolves with an array of configured rollout handler names
rollout
Tests
make test
User Interface
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.
License MIT
Happy rollout!