@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.
Files changed (3) hide show
  1. package/README.md +13 -12
  2. package/SKILL.md +26 -32
  3. 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
- 依赖 `@hile/core` 与 `ioredis`,请一并安装。
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
- 行为:服务在首次加载时创建连接并等待 `connect` 事件;进程退出时通过 Hile 的 shutdown 调用 `client.disconnect()`。
35
+ 行为说明:
36
+
37
+ - 服务首次加载时创建连接并等待 `connect` 事件
38
+ - 进程退出时通过 Hile 的 shutdown 调用 `client.disconnect()`
38
39
 
39
40
  ## 与 @hile/cli 一起使用
40
41
 
41
- 若使用 `@hile/cli` 启动应用,可在项目根 `package.json` 中配置自动加载本包默认服务:
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
- 之后在业务中直接 `loadService(ioredisService)` 即可,Redis 客户端会在应用启动时连接、退出时断开。
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: Code generation and usage rules for @hile/ioredis. Use when editing this package or when the user asks about @hile/ioredis, Redis as Hile service, or loadService(ioredisService) patterns.
3
+ description: @hile/ioredis 的代码生成与使用规范。适用于 Redis 服务加载、环境变量配置、及与 @hile/core/@hile/cli 集成场景。
4
4
  ---
5
5
 
6
- # @hile/ioredis
6
+ # @hile/ioredis SKILL
7
7
 
8
- 本文档是面向 AI 编码模型和人类开发者的 **代码生成规范**,阅读后应能正确地使用本库编写符合架构规则的代码。
8
+ 本文档规范 `@hile/ioredis` 的使用方式,确保 Redis 客户端生命周期由 Hile 统一管理。
9
9
 
10
- ---
11
-
12
- ## 1. 架构总览
13
-
14
- `@hile/ioredis` 在 `@hile/core` 之上提供:
10
+ ## 1. 架构概览
15
11
 
16
- - **默认导出**:一个通过 `defineService` 定义的 **ioredis Redis 客户端** 服务,配置来自环境变量;创建后等待 `connect` 事件再 resolve,进程退出时通过 `shutdown` 注册 `client.disconnect()`。
12
+ `@hile/ioredis` 提供一个默认导出的 Hile 服务:
17
13
 
18
- 依赖:`@hile/core`、`ioredis`。生成代码时必须遵循 Hile 的服务定义与加载规则,通过 `loadService` 获取 Redis 实例并使用 ioredis 的标准 API。
14
+ - 使用环境变量构建 ioredis 客户端
15
+ - 首次加载时建立连接并等待 `connect`
16
+ - 进程退出时调用 `client.disconnect()`
19
17
 
20
- ---
21
-
22
- ## 2. 类型与环境变量
18
+ 依赖:`@hile/core`、`ioredis`。
23
19
 
24
- ### 2.1 环境变量(默认服务)
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 数据库编号,未设置时默认为 `0` |
33
-
34
- 行为:服务在 `new Redis(options)` 后监听 `connect`,连接成功后才 resolve;`shutdown` 时调用 `client.disconnect()`。
28
+ | `REDIS_DB` | Redis 数据库编号(默认 `0`) |
35
29
 
36
- ### 2.2 类型(生成代码时须遵循)
30
+ ## 3. 标准模板
37
31
 
38
- - 默认服务:`defineService(async (shutdown) => { ... return client; })`,返回值为 ioredis 的 `Redis` 实例。
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
- ### 3.2 规则与反模式
43
+ ## 4. 强制规则
44
+
45
+ 1. 统一通过 `loadService(ioredisService)` 获取 Redis 客户端。
46
+ 2. 不要再额外封装一个同用途的全局 Redis 单例与本包混用。
47
+ 3. 生产环境应通过 `REDIS_*` 变量配置,避免硬编码。
48
+ 4. 依赖 Redis 的服务应在服务函数内部加载,不在模块顶层缓存实例。
49
+
50
+ ## 5. API 速查
57
51
 
58
- - 不要在本包外再包一层 `defineService` 封装同一个 Redis 连接;直接使用默认服务即可。
59
- - 不要忽略环境变量:生产环境必须通过 `REDIS_*` 配置,避免硬编码。
60
- - 需要扩展配置时,应在本包内扩展环境变量或 options 构造方式,保持单例由 Hile 管理。
52
+ | 导出 | 说明 |
53
+ |---|---|
54
+ | 默认导出 | Hile 服务化 Redis 客户端 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/ioredis",
3
- "version": "1.0.7",
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.16",
23
+ "@hile/core": "^1.0.17",
24
24
  "ioredis": "^5.10.0"
25
25
  },
26
- "gitHead": "a6eab4e7803f0df7d4bca9a0bdeca76692dbc883"
26
+ "gitHead": "6672fc4cdc551c4265912cc85ee2e96fc44bc4c9"
27
27
  }