@3-/ioredis 0.1.4 → 0.1.6
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 +65 -1
- package/lib.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @3-/
|
|
1
|
+
# @3-/tmpl
|
|
2
2
|
|
|
3
3
|
[English](#en) | [中文](#zh)
|
|
4
4
|
|
|
@@ -7,11 +7,75 @@
|
|
|
7
7
|
<a id="en"></a>
|
|
8
8
|
# README
|
|
9
9
|
|
|
10
|
+
This project provides an optimized ioredis configuration to improve concurrency performance and stability.
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
### enableAutoPipelining: true
|
|
15
|
+
Automatically groups multiple Redis commands into a single network packet within the same event loop tick.
|
|
16
|
+
Significantly reduces Round Trip Time (RTT) and increases throughput for high-frequency operations.
|
|
17
|
+
|
|
18
|
+
### enableOfflineQueue: true
|
|
19
|
+
Enables the command queue when the Redis connection is lost. New commands will be stored in memory and executed automatically once the connection is restored.
|
|
20
|
+
Ensures that application requests do not fail immediately during brief Redis hiccups or reconnections, improving fault tolerance.
|
|
21
|
+
|
|
22
|
+
### keepAlive: 10000 (TCP KeepAlive)
|
|
23
|
+
Sends a TCP keep-alive probe every 10 seconds.
|
|
24
|
+
Prevents network devices (firewalls, load balancers) from silently dropping idle connections.
|
|
25
|
+
|
|
26
|
+
### connectTimeout: 5000
|
|
27
|
+
Sets the connection establishment timeout to 5 seconds.
|
|
28
|
+
Avoids indefinite waiting when the network is poor or Redis is down.
|
|
29
|
+
|
|
30
|
+
### dropBufferSupport: true
|
|
31
|
+
Disables buffer return values to reduce memory copying and CPU overhead.
|
|
32
|
+
Optimized for applications that primarily handle string data.
|
|
33
|
+
|
|
34
|
+
### maxRetriesPerRequest: 3
|
|
35
|
+
Limits retries for a single Redis command to 3 attempts.
|
|
36
|
+
Implements a fail-fast strategy to prevent blocked requests from consuming resources indefinitely.
|
|
37
|
+
|
|
38
|
+
### retryStrategy
|
|
39
|
+
Optimized reconnection logic. Returns an Error object after 6 failed attempts.
|
|
40
|
+
Ensures ioredis terminates the reconnection process gracefully and emits an error event, preventing process crashes.
|
|
41
|
+
|
|
10
42
|
---
|
|
11
43
|
|
|
12
44
|
<a id="zh"></a>
|
|
13
45
|
# 项目说明
|
|
14
46
|
|
|
47
|
+
本项目对 ioredis 进行了默认优化配置,以提高并发性能并增强稳定性。
|
|
48
|
+
|
|
49
|
+
## 参数解析
|
|
50
|
+
|
|
51
|
+
### enableAutoPipelining: true (自动流水线)
|
|
52
|
+
在同一个事件循环周期内,将多个 Redis 命令自动合并为一个网络包发送。
|
|
53
|
+
大幅减少网络往返次数 (RTT),显著提升高频小操作的吞吐量。
|
|
54
|
+
|
|
55
|
+
### enableOfflineQueue: true (启用离线队列)
|
|
56
|
+
当 Redis 连接断开时,将新发出的命令缓存在内存中,待连接恢复后自动执行。
|
|
57
|
+
确保在 Redis 瞬时抖动或短暂断开时,应用层的请求不会直接报错,提升系统的容错性。
|
|
58
|
+
|
|
59
|
+
### keepAlive: 10000 (TCP 保活)
|
|
60
|
+
每 10 秒发送一次 TCP 心跳包。
|
|
61
|
+
防止网络设备(如防火墙、负载均衡器)因连接长时间空闲而主动切断 Socket。
|
|
62
|
+
|
|
63
|
+
### connectTimeout: 5000 (连接超时)
|
|
64
|
+
设置建立连接的超时时间为 5 秒。
|
|
65
|
+
避免在网络环境极差或 Redis 宕机时,应用进程陷入无限制的等待。
|
|
66
|
+
|
|
67
|
+
### dropBufferSupport: true (禁用 Buffer 支持)
|
|
68
|
+
强制 ioredis 不再处理 Buffer 类型的返回值。
|
|
69
|
+
减少内存拷贝和 CPU 转换开销,适用于主要处理字符串数据的场景。
|
|
70
|
+
|
|
71
|
+
### maxRetriesPerRequest: 3 (单次请求重试)
|
|
72
|
+
单个 Redis 命令在失败后最多重试 3 次。
|
|
73
|
+
实现快速失败 (Fail Fast) 策略,避免单个阻塞请求长时间占用资源。
|
|
74
|
+
|
|
75
|
+
### retryStrategy (重连策略)
|
|
76
|
+
优化了重连逻辑。当重连尝试超过 6 次后,返回错误对象。
|
|
77
|
+
确保 ioredis 能够终止重连流程,并触发 error 事件,避免进程因未捕获异常而崩溃。
|
|
78
|
+
|
|
15
79
|
---
|
|
16
80
|
|
|
17
81
|
## About
|
package/lib.js
CHANGED
|
@@ -4,11 +4,16 @@ export default (option) => {
|
|
|
4
4
|
option = {
|
|
5
5
|
retryStrategy: (times) => {
|
|
6
6
|
if (times > 6) {
|
|
7
|
-
|
|
7
|
+
return new Error("ioredis can't connect " + JSON.stringify(option, null, 2));
|
|
8
8
|
}
|
|
9
9
|
return 1e3;
|
|
10
10
|
},
|
|
11
11
|
enableAutoPipelining: true,
|
|
12
|
+
enableOfflineQueue: true,
|
|
13
|
+
keepAlive: 1e4,
|
|
14
|
+
connectTimeout: 5e3,
|
|
15
|
+
dropBufferSupport: true,
|
|
16
|
+
maxRetriesPerRequest: 3,
|
|
12
17
|
...(option || {}),
|
|
13
18
|
};
|
|
14
19
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@3-/ioredis","version":"0.1.
|
|
1
|
+
{"name":"@3-/ioredis","version":"0.1.6","keywords":[],"description":"","repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"homepage":"https://atomgit.com/i18n/lib/tree/dev/ioredis","author":"i18n.site@gmail.com","license":"MulanPSL-2.0","exports":{".":"./lib.js","./*":"./*"},"files":["./*"],"devDependencies":{},"scripts":{},"type":"module","dependencies":{"ioredis":"^5.10.1"}}
|