Skip to content

Commit dbcf3d7

Browse files
committed
document @commandkit/legacy and @commandkit/redis
1 parent 2025fbc commit dbcf3d7

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
11
---
22
title: '@commandkit/legacy'
33
---
4+
5+
:::danger
6+
7+
This plugin is not recommended as we do not plan to continue
8+
supporting the legacy structure. We only recommend this if you're
9+
trying to incrementally upgrade your application. If you prefer the
10+
old way, you can use v0.1.10, but please note, that version is not
11+
actively maintained.
12+
13+
:::
14+
15+
The `@commandkit/legacy` plugin enables support for legacy command and
16+
event handlers. This is particularly useful when migrating from an
17+
older version of CommandKit or another framework, as it allows you to
18+
incrementally upgrade your application without requiring immediate
19+
major changes to your existing code.
20+
21+
## Installation
22+
23+
```sh npm2yarn
24+
npm install @commandkit/legacy
25+
```
26+
27+
## Usage
28+
29+
Add the Legacy plugin to your CommandKit configuration:
30+
31+
```js
32+
import { defineConfig } from 'commandkit';
33+
import { legacy } from '@commandkit/legacy';
34+
35+
export default defineConfig({
36+
plugins: [legacy()],
37+
});
38+
```
39+
40+
## Features
41+
42+
The Legacy plugin provides the following features:
43+
44+
1. **Legacy Command Handler Support**: Enables support for older
45+
command handler formats, making migration easier.
46+
47+
2. **Legacy Event Handler Support**: Allows you to continue using your
48+
existing event handler structure.
49+
50+
3. **Legacy Validation Support**: Maintains compatibility with
51+
existing validation methods.
52+
53+
4. **Hot Module Replacement (HMR)**: The plugin automatically enables
54+
HMR for legacy commands, events, and validations, improving the
55+
development experience by allowing you to see changes without
56+
restarting your bot.
57+
58+
## Migration Strategy
59+
60+
The Legacy plugin is designed as a transitional tool. While it allows
61+
you to continue using your existing code structure, it's recommended
62+
to gradually migrate your commands, events, and validators to the new
63+
CommandKit format over time.
64+
65+
This approach enables you to:
66+
67+
1. Upgrade your bot's framework immediately without breaking existing
68+
functionality
69+
2. Incrementally refactor your code at your own pace
70+
3. Take advantage of new CommandKit features for new commands while
71+
maintaining backward compatibility
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
11
---
22
title: '@commandkit/redis'
33
---
4+
5+
The `@commandkit/redis` plugin provides a cache provider for
6+
CommandKit that allows you to store data in Redis. It works out of the
7+
box with the [`@commandkit/cache`](./03-commandkit-cache.mdx) plugin.
8+
9+
## Installation
10+
11+
```sh npm2yarn
12+
npm install @commandkit/redis
13+
```
14+
15+
## Usage
16+
17+
This plugin will automatically register the Redis cache provider with
18+
your CommandKit instance.
19+
20+
```js
21+
import { defineConfig } from 'commandkit';
22+
import { redis } from '@commandkit/redis';
23+
24+
export default defineConfig({
25+
plugins: [redis()],
26+
});
27+
```
28+
29+
Once configured, your cache functions will automatically use Redis as
30+
the storage backend:
31+
32+
```ts
33+
async function getCachedData() {
34+
'use cache'; // This directive enables caching for the function
35+
36+
// Your data retrieval logic
37+
const data = await getFromDatabase('something');
38+
39+
return data;
40+
}
41+
```
42+
43+
## Manual Configuration
44+
45+
If you need more control over the Redis client configuration, you can
46+
set up the cache provider manually instead of using the plugin:
47+
48+
```ts
49+
import { setCacheProvider } from '@commandkit/cache';
50+
import { RedisCacheProvider } from '@commandkit/redis';
51+
import { Redis } from 'ioredis';
52+
53+
// Configure the Redis client with custom options
54+
const redis = new Redis({
55+
host: 'your-redis-host',
56+
port: 6379,
57+
// Add other Redis options as needed
58+
});
59+
60+
const redisProvider = new RedisCacheProvider(redis);
61+
62+
// Register the provider with CommandKit
63+
setCacheProvider(redisProvider);
64+
```
65+
66+
This approach gives you full control over the Redis client
67+
configuration while still integrating with CommandKit's caching
68+
system.

0 commit comments

Comments
 (0)