This class is a basic in-memory database adapter.
export interface InMemSetValueOptions {
key: string;
value: unknown;
expiresIn?: number;
}
export interface InMemIsKeyExpiredOptions {
value: Record<string, unknown>;
banTimeInSecond: number;
}
import { MemoryAdapter } from "@myunisoft/redis";
const memoryAdapter = new MemoryAdapter();
this method is used to set a key-value pair in memory
const key = "foo";
const value = {
foo: "bar",
};
await memoryAdapter.setValue({ key, value });
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
this method is used to get a value from memory
const key = "foo";
const result = await memoryAdapter.getValue(key);
console.log(result); // { foo: "bar" }
this method is used to clear all key-value pairs in memory
await memoryAdapter.flushall();