upring-kv
v0.5.0
Published
Key-Value store plugin for UpRing
Downloads
11
Readme
upring-kv
Key Value store plugin for UpRing.
Install
npm i upring-kv --save
Usage
This library exposes the standard upring
plugin interface.
Once you register it, it adds a kv
name space with the API documented below.
const upring = require('upring')({
logLevel: 'info',
base: [],
hashring: {
joinTimeout: 200,
replicaPoints: 10
}
})
upring.use(require('upring-kv'))
upring.on('up', onReady)
function onReady () {
upring.kv.put('hello', 'world', onPut)
}
function onPut (err) {
if (err) {
return upring.logger.error(err)
}
upring.kv.get('hello', onGet)
}
function onGet (err, value) {
if (err) {
return upring.logger.error(err)
}
console.log(value)
upring.close()
}
API
- kv#get()
- kv#put()
- kv#liveUpdates()
kv.get(key, cb(err, value))
Get a value from the hashring.
async-await is supported as well:
await upring.kv.get('key')
kv.put(key, value, cb(err))
Put value
in the hashring for the given key.
async-await is supported as well:
await upring.kv.put('key', 'value')
kv.liveUpdates(key)
Returns a Readable
stream in objectMode, which will include
all updates of given key
.
It will emit the last value that was put
, and it will re-emit
it when reconnecting between multiple hosts.
Acknowledgements
This project is kindly sponsored by nearForm.
License
MIT