https://github.com/eldimious/in-memory-database
https://github.com/eldimious/in-memory-database
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eldimious/in-memory-database
- Owner: eldimious
- License: apache-2.0
- Created: 2022-02-12T18:11:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-15T07:45:29.000Z (over 4 years ago)
- Last Synced: 2025-10-06T12:42:48.398Z (10 months ago)
- Language: TypeScript
- Size: 85 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Welcome to in-memory-database module 👋
> Simple caching module that works a like memcached. All keys are stored in a single object.
## Install
```sh
npm install --save in-memory-database
```
## Usage
```ts
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.
```ts
client.get('key');
```
> `set(key: string, value: any): void`
Sets a key to value.
```ts
client.set('key', 'value');
```
> `delete(key: string): void`
Deletes a key.
```ts
client.delete('key');
```
> `mget(keys: string[]): any`
Lists all of the keys that defined in the array.
```ts
const values = client.mget(['key1', 'key2']);
```
> `mset(keyValueMap: Map): void`
Sets the multiple a keys/values.
```ts
const keyValueMap: Map = new Map();
keyValueMap.set('key1', 'value1');
keyValueMap.set('key2', {'foo': 'bar', 'baz': 1});
client.mset(keyValueMap);
```
> `keys(): string[]`
Get all database keys.
```ts
const keys = client.keys();
```
> `has(key: string): boolean`
Defines if we have stored specific key in database.
```ts
const isAlreadyThere = client.has('key');
```
> `flush(): void`
Flush database.
```ts
client.flush();
```
## Run tests
```sh
npm run test
```
## Author
👤 **Dimos Botsaris**
* Website: https://www.eldimious.com
* Twitter: [@el_dimious](https://twitter.com/el_dimious)
* Github: [@eldimious](https://github.com/eldimious)
* LinkedIn: [@dimosthenis-botsaris-5ab16485](https://www.linkedin.com/in/dimosthenis-botsaris-5ab16485/)
## Support Me
[](https://ko-fi.com/Y8Y797KCA)
## Show your support
Give a ⭐️ if this project helped you!