New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

memory-kv-store

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memory-kv-store

A simple in-memory key/value store.

latest
Source
npmnpm
Version
10.0.0
Version published
Maintainers
1
Created
Source

memory-kv-store

A simple in-memory key/value store.

GitHub license

This simple project is intended to mock real key value stores likes Redis or file system based stores. It can also be used in local scripts to run code that assume a key value store exists.

It requires a delay services to be passed in, you can find an implementation in the common-services project.

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, [ttl]) ⇒ Promise.<void>

Set a value in the store

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

ParamTypeDescription
keyStringThe key to store the value at
value*The value to store
[ttl]numberThe duration in milliseconds the value remains valid

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.

ParamTypeDescription
keyStringThe key that map to the value

Example

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

kV.delete(key) ⇒ Promise.<void>

Delete a value from the store

Kind: instance method of KV
Returns: Promise.<void> - A promise that resolve once the value is deleted.

ParamTypeDescription
keyStringThe keyof the deleted value

Example

kv.delete('hello');
.then((value) => console.log('Deleted!'));
// Prints: Deleted!

kV.bulkSet(keys, values, [ttls]) ⇒ Promise.<void>

Set a several values in the store

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

ParamTypeDescription
keysArray.StringThe keys to store the values at
valuesArrayThe values to store
[ttls]Array.numberThe duration in milliseconds each values remains valid

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.

ParamTypeDescription
keysArray.StringThe keys to retrieve the values

Example

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

kV.bulkDelete(keys) ⇒ Promise.<void>

Delete values for several keys from the store

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

ParamTypeDescription
keysArray.StringThe keys for which to delete the values

Example

kv.bulkDelete(['hello', 'foo']);
.then((values) => console.log('Deleted!'));
// Prints: Deleted!

initKV(services) ⇒ Promise.<KV>

Instantiate the kv service

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

ParamTypeDescription
servicesObjectThe services to inject
services.delayfunctionA delaying function
services.timefunctionA timing function
[services.log]functionA logging function
[services.KV_TTL]NumberThe store time to live
[services.KV_STORE]MapThe store for values as a simple object, it is useful to get a synchronous access to the store in tests for example.

Example

import initKV from 'memory-kv-store';

const kv = await initKV({
  delay: Promise.delay.bind(Promise),
});

Authors

License

MIT

FAQs

Package last updated on 27 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts