{"_id":"@1-/redis","_rev":"2-a3c6b6e59ae9234d7f0a290e1c7ba308","name":"@1-/redis","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@1-/redis","version":"0.1.0","keywords":["cluster","ioredis","lifecycle","redis","sentinel"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/redis@0.1.0","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/redis","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"a29338774f40483664f59b34ddf7c7b6afb94a0e","tarball":"https://registry.npmjs.org/@1-/redis/-/redis-0.1.0.tgz","fileCount":9,"integrity":"sha512-SfRqNtQ+J1/16xlJXkQmCwisckBdtjxOED4YNdircGn0R/fxXDjzGzxxMxeJiJbMKPkve8YUfDEm/eNuwlZAXw==","signatures":[{"sig":"MEYCIQCZUFZu6b5MjRPBc4DfYfulpvDD4wIX72knArC0k3uFQQIhAMGGCBUSei9/9zrn/KaPjfzmT0q/vCTP/HK2Dx25wqfi","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13726},"type":"module","exports":{".":"./_.js","./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.16.0","description":"Redis and Cluster client wrapper with environmental configuration support / 支持环境变量配置的 Redis 与 Cluster 客户端封装","directories":{},"_nodeVersion":"26.2.0","dependencies":{"@3-/int":"^0.1.1","ioredis":"^5.11.1","@3-/read":"^0.1.4"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/redis_0.1.0_1781773153828_0.03997942324423498","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@1-/redis","version":"0.1.1","description":"Redis and Cluster client wrapper with environmental configuration support / 支持环境变量配置的 Redis 与 Cluster 客户端封装","keywords":["cluster","ioredis","lifecycle","redis","sentinel"],"homepage":"https://github.com/webc-site/npm/tree/main/redis","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"type":"module","exports":{".":"./_.js","./*":"./*"},"dependencies":{"@3-/int":"^0.1.1","@3-/read":"^0.1.4","ioredis":"^5.11.1"},"_id":"@1-/redis@0.1.1","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-yGTGLeZy2nsbSPQSVBgpXoyVUIC2LVCcOHHgvPyap3WlJWomul0PJkFZH6hV82FWt5F2bYqzPd4hcyWilwm2nw==","shasum":"234462890197f4d06a050b77d4ef8fc09adea248","tarball":"https://registry.npmjs.org/@1-/redis/-/redis-0.1.1.tgz","fileCount":9,"unpackedSize":13745,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICA+O3UjUsJfp4cCqbtrgSx8m+6/qPPX5gwGYtyumsB5AiEAzDD3Mnaghn9RvWu+ur/TjUfeSLPVydAJYOFuYQrGKBw="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/redis_0.1.1_1781774730197_0.33443374340049714"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-18T08:59:13.612Z","modified":"2026-06-18T09:25:30.540Z","0.1.0":"2026-06-18T08:59:13.994Z","0.1.1":"2026-06-18T09:25:30.365Z"},"bugs":{"url":"https://github.com/webc-site/npm/issues"},"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","homepage":"https://github.com/webc-site/npm/tree/main/redis","keywords":["cluster","ioredis","lifecycle","redis","sentinel"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"description":"Redis and Cluster client wrapper with environmental configuration support / 支持环境变量配置的 Redis 与 Cluster 客户端封装","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @1-/redis : Low-coupling, high-cohesion Redis client wrapper with environment-driven configuration\n\n- [@1-/redis : Low-coupling, high-cohesion Redis client wrapper with environment-driven configuration](#1-redis-low-coupling-high-cohesion-redis-client-wrapper-with-environment-driven-configuration)\n  - [Functionality](#functionality)\n  - [Usage Demo](#usage-demo)\n    - [Installation](#installation)\n    - [Single Node Mode](#single-node-mode)\n    - [Cluster Mode](#cluster-mode)\n    - [Sentinel Mode](#sentinel-mode)\n    - [Environment-Driven Mode](#environment-driven-mode)\n  - [Design Rationale](#design-rationale)\n  - [Technical Stack](#technical-stack)\n  - [Code Structure](#code-structure)\n  - [Historical Context](#historical-context)\n  - [About](#about)\n\n- [Functionality](#functionality)\n- [Usage Demo](#usage-demo)\n- [Design Rationale](#design-rationale)\n- [Technical Stack](#technical-stack)\n- [Code Structure](#code-structure)\n- [Historical Context](#historical-context)\n\n## Functionality\n\nThis package provides a lightweight wrapper around `ioredis` for Redis connections in three modes: single node, sentinel, and cluster. It features automatic resource disposal via JavaScript's `Symbol.dispose` and `Symbol.asyncDispose`, enabling safe connection management with the `using` statement. Configuration is driven by environment variables or `.env` files, with automatic mode detection based on variable presence and format.\n\n## Usage Demo\n\n### Installation\n\n```bash\nnpm install @1-/redis\n```\n\n### Single Node Mode\n\n```javascript\nimport one from \"@1-/redis/one.js\";\n\n// host, port, password, db\nconst client = one(\"127.0.0.1\", 6379, \"password\", 0);\n// Use client...\nclient.disconnect();\n```\n\n### Cluster Mode\n\n```javascript\nimport cluster from \"@1-/redis/cluster.js\";\n\n// Space-separated nodes, password\nconst client = cluster(\"127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002\", \"password\");\n// Use client...\nclient.disconnect();\n```\n\n### Sentinel Mode\n\n```javascript\nimport sentinel from \"@1-/redis/sentinel.js\";\n\n// Space-separated sentinel nodes, master name, sentinel password, Redis password\nconst client = sentinel(\"127.0.0.1:26379 127.0.0.1:26380\", \"mymaster\", \"sentinel_pwd\", \"pwd\");\n// Use client...\nclient.disconnect();\n```\n\n### Environment-Driven Mode\n\nCreate a configuration file (e.g., `redis.env`):\n\n```env\nR_NODE='127.0.0.1:6379'\nR_PASSWORD='password'\nR_DB='0'\n```\n\nOr for sentinel:\n\n```env\nR_NODE='127.0.0.1:26379 127.0.0.1:26380'\nR_PASSWORD='password'\nR_SENTINEL_NAME='mymaster'\nR_SENTINEL_PASSWORD='sentinel_password'\n```\n\nOr for cluster:\n\n```env\nR_NODE='127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002'\nR_PASSWORD='password'\n```\n\nThen initialize dynamically:\n\n```javascript\nimport fromEnv from \"@1-/redis\";\n\n// path, prefix (default: \"R\")\nconst client = fromEnv(\"./redis.env\", \"R\");\n// Use client...\nclient.disconnect();\n```\n\nOr using custom environment dictionary:\n\n```javascript\nimport { env } from \"@1-/redis\";\n\nconst client = env(process.env, \"R\");\n// Use client...\nclient.disconnect();\n```\n\n## Design Rationale\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@EV/IhcxjgquOHAR4O4bFIbg.svg)\n\n- **High Cohesion**: Configuration merging and client instantiation logic are centralized in `redis.js`\n- **Automatic Resource Management**: Implements both `Symbol.dispose` and `Symbol.asyncDispose` for deterministic connection cleanup\n- **Environment-Driven Routing**: Connection mode is automatically selected based on environment variable patterns\n- **Low Coupling**: Individual modules handle only parameter transformation; core logic remains in `redis.js`\n\n## Technical Stack\n\n- **Runtime Environment**: Node.js >= 20.12.0 / Bun\n- **Redis Client**: `ioredis` v5.11.1\n- **Utility Libraries**: `@3-/int`, `@3-/read`\n- **Development Tools**: `oxfmt`, `oxlint`\n\n## Code Structure\n\n```\nsrc/\n├── _.js           # Package entry point: reads env files and re-exports env.js\n├── env.js         # Core routing module: selects connection mode based on environment variables\n├── redis.js       # Core instantiation module: handles option merging and lifecycle binding\n├── one.js         # Single node connection module\n├── sentinel.js    # Sentinel connection module\n├── cluster.js     # Cluster connection module\n└── nodeSplit.js   # Node parsing utility: converts space-separated addresses to [host, port] arrays\n```\n\n## Historical Context\n\nRedis (Remote Dictionary Server) was created by Salvatore Sanfilippo (antirez) in 2009 as a solution to scalability limitations in relational databases for his real-time web analytics service LLOOGG. Redis Sentinel was introduced in 2012 to provide high availability through automatic failover, and Redis Cluster was released in 2015 with Redis 3.0 to enable horizontal scaling without proxies.\n\n\n## About\n\nThis library is developed by [WebC.site](https://webc.site).\n\n[WebC.site](https://webc.site): A new paradigm of web development for AI\n\n\n---\n\n<a id=\"zh\"></a>\n# @1-/redis : 低耦合高内聚的 Redis 客户端封装及环境驱动配置方案\n\n- [@1-/redis : 低耦合高内聚的 Redis 客户端封装及环境驱动配置方案](#1-redis-低耦合高内聚的-redis-客户端封装及环境驱动配置方案)\n  - [功能介绍](#功能介绍)\n  - [使用演示](#使用演示)\n    - [安装](#安装)\n    - [单节点模式](#单节点模式)\n    - [集群模式](#集群模式)\n    - [哨兵模式](#哨兵模式)\n    - [环境驱动模式](#环境驱动模式)\n  - [设计思路](#设计思路)\n  - [技术栈](#技术栈)\n  - [代码结构](#代码结构)\n  - [历史故事](#历史故事)\n  - [关于](#关于)\n\n- [功能介绍](#功能介绍)\n- [使用演示](#使用演示)\n- [设计思路](#设计思路)\n- [技术栈](#技术栈)\n- [代码结构](#代码结构)\n- [历史故事](#历史故事)\n\n## 功能介绍\n\n本项目提供 `ioredis` 的轻量级封装，支持单节点、哨兵和集群三种 Redis 连接模式。通过 JavaScript 的 `Symbol.dispose` 和 `Symbol.asyncDispose` 实现自动资源释放，支持 `using` 语句进行安全的连接管理。配置采用环境变量或 `.env` 文件驱动，根据变量存在状态和格式自动识别连接模式。\n\n## 使用演示\n\n### 安装\n\n```bash\nnpm install @1-/redis\n```\n\n### 单节点模式\n\n```javascript\nimport one from \"@1-/redis/one.js\";\n\n// host, port, password, db\nconst client = one(\"127.0.0.1\", 6379, \"password\", 0);\n// 使用客户端...\nclient.disconnect();\n```\n\n### 集群模式\n\n```javascript\nimport cluster from \"@1-/redis/cluster.js\";\n\n// 空格分隔的节点地址，密码\nconst client = cluster(\"127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002\", \"password\");\n// 使用客户端...\nclient.disconnect();\n```\n\n### 哨兵模式\n\n```javascript\nimport sentinel from \"@1-/redis/sentinel.js\";\n\n// 空格分隔的哨兵节点，主节点名，哨兵密码，Redis 密码\nconst client = sentinel(\"127.0.0.1:26379 127.0.0.1:26380\", \"mymaster\", \"sentinel_pwd\", \"pwd\");\n// 使用客户端...\nclient.disconnect();\n```\n\n### 环境驱动模式\n\n创建配置文件（例如 `redis.env`）：\n\n```env\nR_NODE='127.0.0.1:6379'\nR_PASSWORD='password'\nR_DB='0'\n```\n\n哨兵配置示例：\n\n```env\nR_NODE='127.0.0.1:26379 127.0.0.1:26380'\nR_PASSWORD='password'\nR_SENTINEL_NAME='mymaster'\nR_SENTINEL_PASSWORD='sentinel_password'\n```\n\n集群配置示例：\n\n```env\nR_NODE='127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002'\nR_PASSWORD='password'\n```\n\n动态初始化：\n\n```javascript\nimport fromEnv from \"@1-/redis\";\n\n// 路径，环境变量前缀（默认 \"R\"）\nconst client = fromEnv(\"./redis.env\", \"R\");\n// 使用客户端...\nclient.disconnect();\n```\n\n或直接使用环境变量字典：\n\n```javascript\nimport { env } from \"@1-/redis\";\n\nconst client = env(process.env, \"R\");\n// 使用客户端...\nclient.disconnect();\n```\n\n## 设计思路\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@Gg/R4q1qx3fNpAG806RakEQ.svg)\n\n- **高内聚**：配置合并与客户端实例化逻辑集中在 `redis.js` 中\n- **自动资源管理**：实现 `Symbol.dispose` 和 `Symbol.asyncDispose`，确保连接确定性释放\n- **环境驱动路由**：根据环境变量存在状态和格式自动选择连接模式\n- **低耦合**：各模块仅负责参数转换，核心逻辑统一在 `redis.js` 中处理\n\n## 技术栈\n\n- **运行时环境**：Node.js >= 20.12.0 / Bun\n- **Redis 客户端**：`ioredis` v5.11.1\n- **辅助库**：`@3-/int`, `@3-/read`\n- **开发工具**：`oxfmt`, `oxlint`\n\n## 代码结构\n\n```\nsrc/\n├── _.js           # 模块入口点：读取 env 文件并重新导出 env.js\n├── env.js         # 核心路由模块：根据环境变量自动选择连接模式\n├── redis.js       # 核心实例化模块：处理配置项合并及生命周期绑定\n├── one.js         # 单节点连接模块\n├── sentinel.js    # 哨兵连接模块\n├── cluster.js     # 集群连接模块\n└── nodeSplit.js   # 节点解析工具：将空格分隔的地址转为 [host, port] 数组\n```\n\n## 历史故事\n\nRedis（远程字典服务器）由 Salvatore Sanfilippo（antirez）于 2009 年创建，旨在解决其实时网络分析服务 LLOOGG 在关系型数据库中遇到的可扩展性限制。Redis Sentinel 于 2012 年发布，通过自动故障转移提供高可用性；Redis Cluster 则于 2015 年随 Redis 3.0 正式发布，实现无需代理的水平扩展能力。\n\n\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n\n","readmeFilename":"README.md"}