-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc(~): updated doc * doc(~): formulations --------- Co-authored-by: Nicolas Hallaert <[email protected]>
- Loading branch information
Showing
10 changed files
with
274 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<h1 align="center"> | ||
MemoryAdapter | ||
</h1> | ||
|
||
<p align="center"> | ||
This class is a basic in-memory database adapter. | ||
</p> | ||
|
||
## Interface | ||
|
||
```ts | ||
export interface InMemSetValueOptions { | ||
key: string; | ||
value: unknown; | ||
expiresIn?: number; | ||
} | ||
|
||
export interface InMemIsKeyExpiredOptions { | ||
value: Record<string, unknown>; | ||
banTimeInSecond: number; | ||
} | ||
``` | ||
|
||
## 📚 Usage | ||
|
||
```ts | ||
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 | ||
|
||
```ts | ||
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 | ||
|
||
```ts | ||
const key = "foo"; | ||
|
||
const result = await memoryAdapter.deleteValue(key); | ||
|
||
console.log(result); // 0 for Failure, 1 for Success | ||
``` | ||
|
||
### clearExpired(options: { banTimeInSecond: number; }): (string | Buffer)[] | ||
|
||
this method is used to clear expired key-value pairs in memory | ||
|
||
```ts | ||
const result = await memoryAdapter.clearExpired({ banTimeInSecond: 10 }); | ||
|
||
console.log(result); // [] | ||
``` | ||
|
||
### getValue(key: string): null | unknown | ||
|
||
this method is used to get a value from memory | ||
|
||
```ts | ||
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 | ||
|
||
```ts | ||
await memoryAdapter.flushall(); | ||
``` |
Oops, something went wrong.