Skip to content

Latest commit

 

History

History
77 lines (52 loc) · 1.26 KB

memory.adapter.md

File metadata and controls

77 lines (52 loc) · 1.26 KB

MemoryAdapter

This class is a basic in-memory database adapter.

Interface

export interface InMemSetValueOptions {
  key: string;
  value: unknown;
  expiresIn?: number;
}

export interface InMemIsKeyExpiredOptions {
  value: Record<string, unknown>;
  banTimeInSecond: number;
}

📚 Usage

import { MemoryAdapter } from "@myunisoft/redis";

const memoryAdapter = new MemoryAdapter();

📜 API

setValue(options: InMemSetValueOptions): Result<KeyType, SetValueError>

this method is used to set a key-value pair in memory

const key = "foo";
const value = {
  foo: "bar",
};

await memoryAdapter.setValue({ key, value });

deleteValue(key: string): number

this method is used to delete a key-value pair in memory

const key = "foo";

const result = await memoryAdapter.deleteValue(key);

console.log(result); // 0 for Failure, 1 for Success

getValue(key: string): null | unknown

this method is used to get a value from memory

const key = "foo";

const result = await memoryAdapter.getValue(key);

console.log(result); // { foo: "bar" }

flushall()

this method is used to clear all key-value pairs in memory

await memoryAdapter.flushall();