Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ekristen/node-consul-kv-cache
This library turns each key change received into an node emitted event, and keeps track so duplicates are not sent
https://github.com/ekristen/node-consul-kv-cache
Last synced: 2 days ago
JSON representation
This library turns each key change received into an node emitted event, and keeps track so duplicates are not sent
- Host: GitHub
- URL: https://github.com/ekristen/node-consul-kv-cache
- Owner: ekristen
- License: mit
- Created: 2016-01-14T22:19:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-15T21:26:11.000Z (about 9 years ago)
- Last Synced: 2025-01-11T21:42:40.778Z (6 days ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# node-consul-kv-cache
[![Build Status](https://travis-ci.org/ekristen/node-consul-kv-cache.svg?branch=master)](https://travis-ci.org/ekristen/node-consul-kv-cache) [![David](https://img.shields.io/david/ekristen/node-consul-kv-cache.svg)]() [![David](https://img.shields.io/david/dev/ekristen/node-consul-kv-cache.svg)]() [![npm](https://img.shields.io/npm/v/consul-kv-cache.svg)]() [![npm](https://img.shields.io/npm/l/consul-kv-cache.svg)]() [![npm](https://img.shields.io/npm/dt/consul-kv-cache.svg)]()
This is designed to be used with `node-consul` and the watch command with `consul.kv.get` this library turns each key change received into an node emitted event, and keeps track so duplicates are not sent.
If multiple key changes are received with single update, the cache library will trigger 2 separate change events.
## Install Instructions
```
npm install consul-kv-cache
```## Example
```javascript
var consul = require('consul')()var ConsulKVCache = require('consul-kv-cache')
var cache = new ConsulKVCache()
consul
.watch({
method: consul.kv.get,
options: {
key: 'me',
recurse: true
}
})
.on('error', function(err) {
console.log('watch error', err)
})
.on('change', cache.update.bind(cache))cache
.on('error', function(err) {
console.log(err)
})
.on('change', function(key) {
console.log(key)
})
```