-
-
Notifications
You must be signed in to change notification settings - Fork 10
Redis repository package #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cf6a470
Add Redis repository package
dahlia a2c2554
Harden Redis repository concurrency
dahlia f95cd7b
Serialize Redis index writes
dahlia 8eb27fb
Close owned Redis clients reliably
dahlia 4722f45
Serialize Redis quote references
dahlia d5601b1
Harden Redis reconnect and quote removal
dahlia f1821cf
Avoid redundant Redis reconnects
dahlia 212b334
Await pending Redis readiness
dahlia 7efa3dc
Harden Redis cleanup edge cases
dahlia 7be1694
Tighten Redis client and cleanup code
dahlia c536bdb
Batch Redis list item fetches
dahlia c65e94a
Assert batched follower fetch keys
dahlia 73cdaa8
Harden Redis repository lifecycle
dahlia fd9d05f
Clarify Redis MGET test naming
dahlia a5a07c6
Stop Redis lock renewal after close
dahlia b4dee2d
List Redis package imports explicitly
dahlia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
| @fedify/botkit-redis | ||
| ==================== | ||
|
|
||
| [![JSR][JSR badge]][JSR] | ||
| [![npm][npm badge]][npm] | ||
| [![GitHub Actions][GitHub Actions badge]][GitHub Actions] | ||
|
|
||
| This package is a [Redis]-based repository implementation for [BotKit]. It | ||
| provides shared persistent storage for bots running on either [Deno] or | ||
| [Node.js], using Redis data structures for BotKit repository data. | ||
|
|
||
| [JSR badge]: https://jsr.io/badges/@fedify/botkit-redis | ||
| [JSR]: https://jsr.io/@fedify/botkit-redis | ||
| [npm badge]: https://img.shields.io/npm/v/@fedify/botkit-redis?logo=npm | ||
| [npm]: https://www.npmjs.com/package/@fedify/botkit-redis | ||
| [GitHub Actions badge]: https://github.com/fedify-dev/botkit/actions/workflows/main.yaml/badge.svg | ||
| [GitHub Actions]: https://github.com/fedify-dev/botkit/actions/workflows/main.yaml | ||
| [Redis]: https://redis.io/ | ||
| [BotKit]: https://botkit.fedify.dev/ | ||
| [Deno]: https://deno.land/ | ||
| [Node.js]: https://nodejs.org/ | ||
|
|
||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
| ~~~~ sh | ||
| deno add jsr:@fedify/botkit-redis | ||
| npm add @fedify/botkit-redis | ||
| pnpm add @fedify/botkit-redis | ||
| yarn add @fedify/botkit-redis | ||
| ~~~~ | ||
|
|
||
|
|
||
| Usage | ||
| ----- | ||
|
|
||
| The `RedisRepository` can be used as a drop-in repository implementation for | ||
| BotKit: | ||
|
|
||
| ~~~~ typescript | ||
| import { createBot, MemoryKvStore } from "@fedify/botkit"; | ||
| import { RedisRepository } from "@fedify/botkit-redis"; | ||
|
|
||
| const bot = createBot({ | ||
| username: "mybot", | ||
| kv: new MemoryKvStore(), | ||
| repository: new RedisRepository({ | ||
| url: "redis://localhost:6379/0", | ||
| prefix: "botkit", | ||
| }), | ||
| }); | ||
| ~~~~ | ||
|
|
||
| You can also inject an existing node-redis client. In that case the | ||
| repository does not own the client and `close()` will not shut it down: | ||
|
|
||
| ~~~~ typescript | ||
| import { RedisRepository } from "@fedify/botkit-redis"; | ||
| import { createClient } from "redis"; | ||
|
|
||
| const client = createClient({ url: "redis://localhost:6379/0" }); | ||
| await client.connect(); | ||
|
|
||
| const repository = new RedisRepository({ | ||
| client, | ||
| prefix: "botkit", | ||
| }); | ||
| ~~~~ | ||
|
|
||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| The `RedisRepository` constructor accepts the following options: | ||
|
|
||
| - **`url`**: A Redis connection string for an internally managed client. | ||
|
|
||
| - **`client`**: An existing node-redis compatible client to use. | ||
|
|
||
| - **`prefix`** (optional): Redis key prefix used for BotKit data. Defaults | ||
| to `"botkit"`. | ||
|
|
||
| - **`clientOptions`** (optional): Additional node-redis client options. | ||
| This option is only valid together with `url`. | ||
|
|
||
| The options are mutually exclusive: use either `client` or `url`. | ||
|
|
||
|
|
||
| Features | ||
| -------- | ||
|
|
||
| - **Cross-runtime**: Works with both Deno and Node.js using node-redis. | ||
|
|
||
| - **Shared persistent storage**: Suitable for multi-process deployments | ||
| backed by Redis. | ||
|
|
||
| - **Key namespacing**: Keeps BotKit data under a configurable Redis prefix. | ||
|
|
||
| - **Full `Repository` API**: Implements BotKit repository storage for key | ||
| pairs, messages, followers, follows, followees, quote authorizations, and | ||
| poll votes. | ||
|
|
||
| - **Explicit resource ownership**: Repositories created from a URL own their | ||
| Redis client, while repositories created from an injected client leave | ||
| lifecycle control to the caller. |
This file contains hidden or 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,24 @@ | ||
| { | ||
| "name": "@fedify/botkit-redis", | ||
| "version": "0.5.0", | ||
| "license": "AGPL-3.0-only", | ||
| "exports": { | ||
| ".": "./src/mod.ts" | ||
| }, | ||
| "imports": { | ||
| "@fedify/vocab": "jsr:@fedify/vocab@^2.3.1", | ||
| "redis": "npm:redis@^6.1.0" | ||
| }, | ||
| "exclude": [ | ||
| "dist", | ||
| "junit.xml", | ||
| "package.json" | ||
| ], | ||
| "fmt": { | ||
| "exclude": [ | ||
| "*.md", | ||
| "*.yaml", | ||
| "*.yml" | ||
| ] | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.