Home

Awesome

upring-kv

npm version Build Status js-standard-style Coverage Status

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


<a name="get"></a>

kv.get(key, cb(err, value))

Get a value from the hashring.
async-await is supported as well:

await upring.kv.get('key')

<a name="put"></a>

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')

<a name="liveUpdates"></a>

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.

<a name="acknowledgements"></a>

Acknowledgements

This project is kindly sponsored by nearForm.

License

MIT