beepboop-persist
v1.0.0
Published
A javascript client to the BeepBoop Persist key/value store
Downloads
25
Readme
Beep Boop Persist Key/Value Store JS Client
This is a node.js client for the Beep Boop Persist service.
Though Persist only stores simple strings, this client will automatically JSON.stringify
and JSON.parse
objects passed
as values.
If running on Beep Boop the below example should just work. If running outside of Beep Boop it will fall back to an in memory store. See further configuration options below.
var kv = require('beepboop-persist')()
kv.set('a key', 'the key, is water', function (err) {
// handle error :)
kv.get('a key', function (err, val) {
// handle error :)
// val should be 'the key, is water'
kv.list(function (err, keys) {
// handle error :)
// keys should be ['a key']
kv.del('a key', function (err) {
// handle error :)
// 'a key' should be deleted
})
})
})
})
BeepBoopPersist([options])
Returns a Beep Boop Perist api:
options.serialize
- defaults totrue
- all values will be run throughJSON.stringify()
andJSON.parse()
options.token
- defaults toprocess.env.BEEPBOOP_TOKEN
- auth token passed into environment by Beep Boopoptions.url
- defaults toprocess.env.BEEPBOOP_PERSIST_URL || process.env.BEEPBOOP_API_URL || 'https://beepboophq.com/api/v1'
- service url passed into environment by Beep Boopoptions.debug
- defaults tofalse
- iftrue
then api calls and errors are logged.options.logger
- defaults tonull
- Should be an object w/ adebug
anderror
function.options.provider
- defaults tonull
, acceptable values are"memory"
,"beepboop"
, or"fs"
- this provides a way to override provider selection logic. If this isn't explicitly set, then the"beepboop"
provider is used when bothtoken
andurl
are present. Otherwise the"memory"
provider is used."fs"
can be used when running outside of Beep Boop to make data survive restarts. This provider shouldn't be used while running on Beep Boop though since the disks are ephemeral.options.directory
- defaults to.persist
under module - Only used with thefs
filesystem provider (meant for testing only) to control where data is stored.
.set(key, value, callback)
Set a value for a key. If value
is not a string it will be JSON.stringify()
'd if options.serialize
is true
let obj = { foo: 'bar', baz: 1 }
kv.set('a key', obj, function (err) {
// check for err
})
.get(key, callback)
Get a value for a key. If val
is a string, it will be passed as such, otherwise it is JSON.parse()
'd if options.serialize
is true
kv.get('a key', function (err, val) {
// check for err
})
.mget(keys, callback)
Get multiple values for a key.
kv.set('key1', 'string value', function (err) {})
kv.set('key2', { foo: 'bar' }, function (err) {})
let keys = ['key1', 'key1', 'non-existent-key']
kv.mget(keys, function (err, result) {
// check for err
// result = ['string value', { foo: 'bar' }, null]
})
.del(key, callback)
Delete a value at a key
kv.del('a key', function (err) {
// check for err
})
.list(begins, callback)
List all keys:
kv.list(function (err, keys) {
// check for err
// keys is array of strings like ['key1', 'key2', 'baz3']
})
List keys that begin with a prefix:
// beings with 'key' for example
kv.list('key', function (err, keys) {
// check for err
// keys is array of strings like ['key1', 'key2']
})