Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binocarlos/etcd-live-collection
A local cache of objects that auto-updates from etcd wait listeners
https://github.com/binocarlos/etcd-live-collection
Last synced: 10 days ago
JSON representation
A local cache of objects that auto-updates from etcd wait listeners
- Host: GitHub
- URL: https://github.com/binocarlos/etcd-live-collection
- Owner: binocarlos
- Created: 2014-08-13T21:05:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-16T14:47:58.000Z (over 10 years ago)
- Last Synced: 2024-09-15T22:21:15.168Z (2 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
etcd-live-collection
--------------------A local cache of objects that auto-updates from etcd wait listeners
## install
```
$ npm install etcd-live-collection
```## usage
Create a collection based on an etcd key - the collection will automatically keep in sync.
```js
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){})
```
## api
#### `var collection = liveCollection(etcdConnection, key)`
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`
#### `var map = collection.values()`
Return all the current values in the collection
Map is a flat object of keys onto values:
```js
{
"/apples/green":10,
"/oranges":12
}
```## events
#### `collection.on('ready', function(){})`
called once when the collection is up and running and has the current values loaded
#### `collection.on('action', function(action, key, value){})`
Called when a change has happened to a value in the collection.
## license
MIT