npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

memory-kv-store

v8.0.2

Published

A simple in-memory key/value store.

Downloads

178

Readme

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

Functions

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.

| Param | Type | Description | | --- | --- | --- | | key | String | The key to store the value at | | value | * | The value to store | | [ttl] | number | The 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.

| Param | Type | Description | | --- | --- | --- | | key | String | The 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.

| Param | Type | Description | | --- | --- | --- | | key | String | The 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.

| Param | Type | Description | | --- | --- | --- | | keys | Array.String | The keys to store the values at | | values | Array | The values to store | | [ttls] | Array.number | The 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.

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

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.

| Param | Type | Description | | --- | --- | --- | | keys | Array.String | The 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

| Param | Type | Description | | --- | --- | --- | | services | Object | The services to inject | | services.delay | function | A delaying function | | services.time | function | A timing function | | [services.log] | function | A logging function | | [services.KV_TTL] | Number | The store time to live | | [services.KV_STORE] | Map | The 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