@hile/ioredis 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/SKILL.md +26 -32
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hile/ioredis
|
|
2
2
|
|
|
3
|
-
基于 `@hile/core` 的 Redis 集成:将 ioredis 客户端封装为 Hile
|
|
3
|
+
基于 `@hile/core` 的 Redis 集成:将 ioredis 客户端封装为 Hile 服务(单例、可优雅断连)。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -8,12 +8,10 @@
|
|
|
8
8
|
pnpm add @hile/ioredis
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
同时安装依赖:`@hile/core`、`ioredis`。
|
|
12
12
|
|
|
13
13
|
## 快速开始
|
|
14
14
|
|
|
15
|
-
通过环境变量配置 Redis,用 `loadService` 获取客户端:
|
|
16
|
-
|
|
17
15
|
```typescript
|
|
18
16
|
import { loadService } from '@hile/core'
|
|
19
17
|
import ioredisService from '@hile/ioredis'
|
|
@@ -24,21 +22,24 @@ const redis = await loadService(ioredisService)
|
|
|
24
22
|
|
|
25
23
|
## 环境变量
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
默认客户端从以下环境变量读取配置:
|
|
28
26
|
|
|
29
27
|
| 变量 | 说明 |
|
|
30
28
|
|------|------|
|
|
31
29
|
| `REDIS_HOST` | Redis 主机 |
|
|
32
|
-
| `REDIS_PORT` | Redis
|
|
30
|
+
| `REDIS_PORT` | Redis 端口(字符串会转为数字) |
|
|
33
31
|
| `REDIS_USERNAME` | Redis 用户名 |
|
|
34
32
|
| `REDIS_PASSWORD` | Redis 密码 |
|
|
35
33
|
| `REDIS_DB` | Redis 数据库编号,默认 `0` |
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
行为说明:
|
|
36
|
+
|
|
37
|
+
- 服务首次加载时创建连接并等待 `connect` 事件
|
|
38
|
+
- 进程退出时通过 Hile 的 shutdown 调用 `client.disconnect()`
|
|
38
39
|
|
|
39
40
|
## 与 @hile/cli 一起使用
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
可在 `package.json` 配置自动加载:
|
|
42
43
|
|
|
43
44
|
```json
|
|
44
45
|
{
|
|
@@ -48,15 +49,15 @@ const redis = await loadService(ioredisService)
|
|
|
48
49
|
}
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
这样应用启动时会自动建立 Redis 连接,退出时自动断开。
|
|
52
53
|
|
|
53
54
|
## 开发
|
|
54
55
|
|
|
55
56
|
```bash
|
|
56
57
|
pnpm install
|
|
57
|
-
pnpm build
|
|
58
|
-
pnpm dev
|
|
59
|
-
pnpm test
|
|
58
|
+
pnpm build
|
|
59
|
+
pnpm dev
|
|
60
|
+
pnpm test
|
|
60
61
|
```
|
|
61
62
|
|
|
62
63
|
## License
|
package/SKILL.md
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: hile-ioredis
|
|
3
|
-
description:
|
|
3
|
+
description: @hile/ioredis 的代码生成与使用规范。适用于 Redis 服务加载、环境变量配置、及与 @hile/core/@hile/cli 集成场景。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# @hile/ioredis
|
|
6
|
+
# @hile/ioredis SKILL
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
本文档规范 `@hile/ioredis` 的使用方式,确保 Redis 客户端生命周期由 Hile 统一管理。
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## 1. 架构总览
|
|
13
|
-
|
|
14
|
-
`@hile/ioredis` 在 `@hile/core` 之上提供:
|
|
10
|
+
## 1. 架构概览
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
`@hile/ioredis` 提供一个默认导出的 Hile 服务:
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
- 使用环境变量构建 ioredis 客户端
|
|
15
|
+
- 首次加载时建立连接并等待 `connect`
|
|
16
|
+
- 进程退出时调用 `client.disconnect()`
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## 2. 类型与环境变量
|
|
18
|
+
依赖:`@hile/core`、`ioredis`。
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
## 2. 环境变量
|
|
25
21
|
|
|
26
22
|
| 变量 | 说明 |
|
|
27
|
-
|
|
23
|
+
|---|---|
|
|
28
24
|
| `REDIS_HOST` | Redis 主机 |
|
|
29
|
-
| `REDIS_PORT` | Redis
|
|
25
|
+
| `REDIS_PORT` | Redis 端口(字符串转数字) |
|
|
30
26
|
| `REDIS_USERNAME` | Redis 用户名 |
|
|
31
27
|
| `REDIS_PASSWORD` | Redis 密码 |
|
|
32
|
-
| `REDIS_DB` | Redis
|
|
33
|
-
|
|
34
|
-
行为:服务在 `new Redis(options)` 后监听 `connect`,连接成功后才 resolve;`shutdown` 时调用 `client.disconnect()`。
|
|
28
|
+
| `REDIS_DB` | Redis 数据库编号(默认 `0`) |
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
## 3. 标准模板
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
- 需要类型时从 `ioredis` 自行引入,例如 `import type { Redis, RedisOptions } from 'ioredis'`;本包仅导出默认服务,不 re-export 类型。
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## 3. 代码生成模板与规则
|
|
44
|
-
|
|
45
|
-
### 3.1 使用默认服务
|
|
32
|
+
### 3.1 加载默认服务
|
|
46
33
|
|
|
47
34
|
```typescript
|
|
48
35
|
import { loadService } from '@hile/core'
|
|
@@ -53,8 +40,15 @@ await redis.set('key', 'value')
|
|
|
53
40
|
const value = await redis.get('key')
|
|
54
41
|
```
|
|
55
42
|
|
|
56
|
-
|
|
43
|
+
## 4. 强制规则
|
|
44
|
+
|
|
45
|
+
1. 统一通过 `loadService(ioredisService)` 获取 Redis 客户端。
|
|
46
|
+
2. 不要再额外封装一个同用途的全局 Redis 单例与本包混用。
|
|
47
|
+
3. 生产环境应通过 `REDIS_*` 变量配置,避免硬编码。
|
|
48
|
+
4. 依赖 Redis 的服务应在服务函数内部加载,不在模块顶层缓存实例。
|
|
49
|
+
|
|
50
|
+
## 5. API 速查
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
| 导出 | 说明 |
|
|
53
|
+
|---|---|
|
|
54
|
+
| 默认导出 | Hile 服务化 Redis 客户端 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/ioredis",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"vitest": "^4.0.18"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@hile/core": "1.0.
|
|
23
|
+
"@hile/core": "^1.0.17",
|
|
24
24
|
"ioredis": "^5.10.0"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "6672fc4cdc551c4265912cc85ee2e96fc44bc4c9"
|
|
27
27
|
}
|