Skip to content

Commit

Permalink
chore: add storages list at docs with tips
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Dec 26, 2024
1 parent 6ca9dff commit 893da76
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
123 changes: 122 additions & 1 deletion docs/storages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GramIO has many ready-made adapters, but you can also write your own!

- In Memory (`@gramio/storage`)

- Redis (`@gramio/storage-redis`)
- [Redis](#redis) (`@gramio/storage-redis`)

## How to write my own storage adapters

Expand Down Expand Up @@ -87,3 +87,124 @@ export function myOwnPlugin(options: MyOwnPluginOptions = {}) {

> [!IMPORTANT]
> You can scaffold this example by [create-gramio-plugin](/plugins/how-to-write.html#scaffolding-the-plugin)
## List

## In Memory

<div class="badges">

[![npm](https://img.shields.io/npm/v/@gramio/storage?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/storage)
[![npm downloads](https://img.shields.io/npm/dw/@gramio/storage?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/storage)
[![JSR](https://jsr.io/badges/@gramio/storage)](https://jsr.io/@gramio/storage)
[![JSR Score](https://jsr.io/badges/@gramio/storage/score)](https://jsr.io/@gramio/storage)

</div>

##### Installation

::: code-group

```bash [npm]
npm install @gramio/storage
```

```bash [yarn]
yarn add @gramio/storage
```

```bash [pnpm]
pnpm add @gramio/storage
```

```bash [bun]
bun install @gramio/storage
```

:::

##### Usage

1. With default [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)

```ts twoslash
import { inMemoryStorage } from "@gramio/storage";

const storage = inMemoryStorage();
```

2. Provide your own [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)

```ts twoslash
import { inMemoryStorage, type InMemoryStorageMap } from "@gramio/storage";

const map: InMemoryStorageMap = new Map();

const storage = inMemoryStorage();
```

## Redis

<div class="badges">

[![npm](https://img.shields.io/npm/v/@gramio/storage-redis?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/storage-redis)
[![npm downloads](https://img.shields.io/npm/dw/@gramio/storage-redis?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/storage-redis)
[![JSR](https://jsr.io/badges/@gramio/storage-redis)](https://jsr.io/@gramio/storage-redis)
[![JSR Score](https://jsr.io/badges/@gramio/storage-redis/score)](https://jsr.io/@gramio/storage-redis)

</div>

##### Installation

::: code-group

```bash [npm]
npm install @gramio/storage-redis
```

```bash [yarn]
yarn add @gramio/storage-redis
```

```bash [pnpm]
pnpm add @gramio/storage-redis
```

```bash [bun]
bun install @gramio/storage-redis
```

:::

##### Usage

1. Provide ioredis options to the `redisStorage` function

```ts twoslash
import { redisStorage } from "@gramio/storage-redis";

const storage = redisStorage({
host: process.env.REDIS_HOST,
});
```

2. Provide ioredis instance to the `redisStorage` function

```ts twoslash
import { redisStorage } from "@gramio/storage-redis";
import { Redis } from "ioredis";

const redis = new Redis({
host: process.env.REDIS_HOST,
});

const storage = redisStorage(redis);
```

##### Tips

For inspecting which data is stored in Redis, we recommend you to use GUI clients like [AnotherRedisDesktopManager](https://github.com/qishibo/AnotherRedisDesktopManager).

<!-- TODO: More GramIO backend screens -->

<img src="https://cdn.jsdelivr.net/gh/qishibo/img/ardm/202411081318490.png" alt="AnotherRedisDesktopManager" />
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@gramio/keyboards": "^1.0.0",
"@gramio/prompt": "^1.1.4",
"@gramio/session": "^0.1.5",
"@gramio/storage": "^1.0.0",
"@gramio/storage-redis": "^1.0.3",
"@gramio/types": "^8.0.3",
"@iconify-json/logos": "^1.2.3",
"@iconify-json/skill-icons": "^1.2.0",
Expand All @@ -35,7 +37,7 @@
"trustedDependencies": ["@biomejs/biome"],
"dependencies": {
"@gramio/scenes": "^0.0.5",
"ioredis": "^5.4.1",
"ioredis": "^5.4.2",
"jobify": "^0.1.1"
}
}

0 comments on commit 893da76

Please sign in to comment.