hile-ioredis
@hile/ioredis SKILL
本文档规范 @hile/ioredis 的使用方式,确保 Redis 客户端生命周期由 Hile 统一管理。
1. 架构概览
@hile/ioredis 提供一个默认导出的 Hile 服务:
- 使用环境变量构建 ioredis 客户端
- 首次加载时建立连接并等待
connect - 进程退出时调用
client.disconnect()
依赖:@hile/core、ioredis。
2. 环境变量
| 变量 | 说明 |
|---|---|
REDIS_HOST |
Redis 主机 |
REDIS_PORT |
Redis 端口(字符串转数字) |
REDIS_USERNAME |
Redis 用户名 |
REDIS_PASSWORD |
Redis 密码 |
REDIS_DB |
Redis 数据库编号(默认 0) |
3. 标准模板
3.1 加载默认服务
import { loadService } from '@hile/core'
import ioredisService from '@hile/ioredis'
const redis = await loadService(ioredisService)
await redis.set('key', 'value')
const value = await redis.get('key')
4. 强制规则
- 统一通过
loadService(ioredisService)获取 Redis 客户端。 - 不要再额外封装一个同用途的全局 Redis 单例与本包混用。
- 生产环境应通过
REDIS_*变量配置,避免硬编码。 - 依赖 Redis 的服务应在服务函数内部加载,不在模块顶层缓存实例。
5. API 速查
| 导出 | 说明 |
|---|---|
| 默认导出 | Hile 服务化 Redis 客户端 |
More from cevio/hile
hile-http
@hile/http 的代码生成与使用规范。适用于路由、控制器、中间件、文件系统自动路由及与 @hile/core 的集成场景。
21hile-typeorm
@hile/typeorm 的代码生成与使用规范。适用于 DataSource 服务加载、transaction 事务封装、及与 @hile/core/@hile/cli 集成场景。
18hile-monorepo
引导 AI 在本仓库或使用 Hile 的项目中,正确选用并遵守各 Hile 模块的约束与用法。编辑/生成涉及 @hile/* 或 create-hile 的代码时必读。凡依赖 @hile/http-next 的应用须同时严格遵守 packages/http-next/SKILL.md 全文,不得选择性遵守。
8message-loader
Code generation and contribution rules for @hile/message-loader. Use when editing this package or when the user asks about @hile/message-loader patterns or API.
1http-next
Code generation and contribution rules for @hile/http-next. Use when editing this package or when the user asks about @hile/http-next patterns or API.
1message-ipc
Code generation and contribution rules for @hile/message-ipc. Use when editing this package or when the user asks about @hile/message-ipc patterns or API.
1