A local cache of objects that auto-updates from etcd wait listeners
$ npm install etcd-live-collection
Create a collection based on an etcd key - the collection will automatically keep in sync.
var liveCollection = require('etcd-live-collection')
var etcdjs = require('etcdjs')
var etcd = etcdjs('127.0.0.1:4001')
var collection = liveCollection(etcd, '/my/key')
// once the collection has initialized with values
collection.on('ready', function(map){
// map is a flat object with etcd keys and values
console.dir(collection.values())
})
// the collection has changed somehow
collection.on('action', function(action, key, value){
})
Create a new collection - etcdConnection can be a connection string or an existing etcdjs object
key is the base key for values to be saved.
If the base key is /apples
and you add a /green
key to the collection then the etcd key will be /apples/green
Return all the current values in the collection
Map is a flat object of keys onto values:
{
"/apples/green":10,
"/oranges":12
}
called once when the collection is up and running and has the current values loaded
Called when a change has happened to a value in the collection.
MIT