in-memory-database
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Welcome to in-memory-database module 👋

Version Documentation Maintenance Twitter: el_dimious

Simple caching module that works a like memcached. All keys are stored in a single object.

Install

npm install --save in-memory-database

Usage

const { InMemoryDatabase } = require('in-memory-database');

const client = new InMemoryDatabase();
client.set('key', 'value');
client.get('key');

Docs

class InMemoryDatabase()

Class Methods

These functions are specified in the in-memory-database.

get(key: string): any

Gets a key'svalue.

client.get('key');

set(key: string, value: any): void

Sets a key to value.

client.set('key', 'value');

delete(key: string): void

Deletes a key.

client.delete('key');

mget(keys: string[]): any

Lists all of the keys that defined in the array.

const values = client.mget(['key1', 'key2']);

mset(keyValueMap: Map<string, any>): void

Sets the multiple a keys/values.

const keyValueMap: Map<string, any> = new Map();
keyValueMap.set('key1', 'value1');
keyValueMap.set('key2', {'foo': 'bar', 'baz': 1});
client.mset(keyValueMap);

keys(): string[]

Get all database keys.

const keys = client.keys();

has(key: string): boolean

Defines if we have stored specific key in database.

const isAlreadyThere = client.has('key');

flush(): void

Flush database.

client.flush();

Run tests

npm run test

Author

👤 Dimos Botsaris

Support Me

ko-fi

Show your support

Give a ⭐️ if this project helped you!

Package Sidebar

Install

npm i in-memory-database

Weekly Downloads

25

Version

1.0.1

License

ISC

Unpacked Size

17.5 kB

Total Files

4

Last publish

Collaborators

  • dimosbotsaris