node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

memory-kv-store

memory-kv-store

A simple in-memory key/value store.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate Dependency Status

API

Classes

KV

Creates a key/value store

Functions

initKV(services)Promise.<KV>

Instantiate the kv service

KV

Creates a key/value store

Kind: global class

kV.set(key, value) ⇒ Promise

Set a value in the store

Kind: instance method of KV
Returns: Promise - A promise to be resolved when the value is stored.

Param Type Description
key String The key to store the value at
value * The value to store

Example

kv.set('hello', 'world');
.then(() => console.log('Stored!'));
// Prints: Stored!

kV.get(key) ⇒ Promise

Get a value from the store

Kind: instance method of KV
Returns: Promise - A promise that resolve to the actual value.

Param Type Description
key String The key that map to the value

Example

kv.get('hello');
.then((value) => console.log(value));
// Prints: world

kV.bulkSet(keys, values) ⇒ Promise

Set a several values in the store

Kind: instance method of KV
Returns: Promise - A promise to be resolved when the values are stored.

Param Type Description
keys Array.String The keys to store the values at
values Array The values to store

Example

kv.bulkSet(['hello', 'foo'], ['world', 'bar']);
.then(() => console.log('Stored!'));
// Prints: Stored!

kV.bulkGet(keys) ⇒ Promise.<Array>

Get a several values from the store

Kind: instance method of KV
Returns: Promise.<Array> - A promise to be resolved when the values are retrieved.

Param Type Description
keys Array.String The keys to retrieve the values

Example

kv.bulkGet(['hello', 'foo']);
.then((values) => console.log(values));
// Prints: ['world', 'bar']

initKV(services) ⇒ Promise.<KV>

Instantiate the kv service

Kind: global function
Returns: Promise.<KV> - A promise of the kv service

Param Type Description
services Object The services to inject
services.delay function A delaying function
[services.log] function A logging function
[services.KV_TTL] Number The store time to live
[services.KV_STORE] Map The store time to live

Example

import initKV from 'memory-kv-store';
 
const kv = await initKV({
  delay: Promise.delay.bind(Promise),
});

License

MIT