mm_redis 2.0.0 → 2.0.1
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 +16 -65
- package/index.js +0 -81
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@ mm_redis是一个高效的Redis客户端封装库,提供了全面的Redis功
|
|
|
7
7
|
|
|
8
8
|
## 版本信息
|
|
9
9
|
|
|
10
|
-
- **当前版本**: 2.0.
|
|
11
|
-
- **更新日期**:
|
|
10
|
+
- **当前版本**: 2.0.1
|
|
11
|
+
- **更新日期**: 2025-10-14
|
|
12
12
|
- **作者**: 邱文武
|
|
13
13
|
- **NPM**: [https://www.npmjs.com/package/mm_redis](https://www.npmjs.com/package/mm_redis)
|
|
14
14
|
- **GitHub**: [https://gitee.com/qiuwenwu91/mm_redis](https://gitee.com/qiuwenwu91/mm_redis)
|
|
@@ -79,6 +79,11 @@ redis.setConfig('./config.json');
|
|
|
79
79
|
```
|
|
80
80
|
## 变更日志
|
|
81
81
|
|
|
82
|
+
### v2.0.0 (2025-10-14)
|
|
83
|
+
- 移除list_push方法,统一使用addForList方法进行列表添加操作
|
|
84
|
+
- 更新文档,将所有list_push引用替换为addForList
|
|
85
|
+
- 更新文档中的API列表和使用示例
|
|
86
|
+
|
|
82
87
|
### v1.9.8 (2024-12-22)
|
|
83
88
|
- 更新文档,完善npm发布所需内容
|
|
84
89
|
- 添加GitHub仓库链接到文档
|
|
@@ -136,7 +141,7 @@ await redis.close();
|
|
|
136
141
|
await redis.setForList('users', ['user1', 'user2', 'user3']);
|
|
137
142
|
|
|
138
143
|
// 添加元素到列表
|
|
139
|
-
await redis.
|
|
144
|
+
await redis.addForList('users', 'user4');
|
|
140
145
|
|
|
141
146
|
// 获取列表
|
|
142
147
|
const users = await redis.getForList('users');
|
|
@@ -291,7 +296,7 @@ redis.on('set_error', (data) => {
|
|
|
291
296
|
| setrange | setrange_before | setrange_after | setrange_error |
|
|
292
297
|
| clear | clear_before | clear_after | clear_error |
|
|
293
298
|
| setForList | setForList_before | setForList_after | setForList_error |
|
|
294
|
-
|
|
|
299
|
+
| addForList | addForList_before | addForList_after | addForList_error |
|
|
295
300
|
| clearForList | clearForList_before | clearForList_after | clearForList_error |
|
|
296
301
|
| mset | mset_before | mset_after | mset_error |
|
|
297
302
|
| mget | mget_before | mget_after | mget_error |
|
|
@@ -335,7 +340,7 @@ redis.on('set_error', (data) => {
|
|
|
335
340
|
### 列表操作
|
|
336
341
|
|
|
337
342
|
- `setForList(key, value, seconds)`: 设置列表
|
|
338
|
-
- `
|
|
343
|
+
- `addForList(key, value)`: 添加元素到列表
|
|
339
344
|
- `getForList(key, start, end)`: 获取列表
|
|
340
345
|
- `hasForList(key, value)`: 判断列表中是否存在元素
|
|
341
346
|
- `clearForList(key, value)`: 清空列表或重置列表
|
|
@@ -423,66 +428,12 @@ redis.on('set_error', (data) => {
|
|
|
423
428
|
|
|
424
429
|
## 版本更新
|
|
425
430
|
|
|
426
|
-
###
|
|
427
|
-
-
|
|
428
|
-
-
|
|
429
|
-
-
|
|
430
|
-
-
|
|
431
|
-
-
|
|
432
|
-
- 修复原生Redis API调用中的错误,提升代码稳定性
|
|
433
|
-
- 优化连接池管理,修复潜在的内存泄漏问题
|
|
434
|
-
|
|
435
|
-
### 1.9.4 (2024-12-20)
|
|
436
|
-
- 优化了配置引入方式,支持对象配置和文件路径配置两种方式
|
|
437
|
-
- 改进了setConfig方法的实现,使用Object.assign替代原来的合并方式
|
|
438
|
-
- 修复了连接池相关的警告信息
|
|
439
|
-
- 增强了错误处理机制
|
|
440
|
-
|
|
441
|
-
### 1.9.0 (2024-11-20)
|
|
442
|
-
- 适配Redis v4 API,确保与最新版Redis客户端兼容
|
|
443
|
-
- 重写pipeline方法,使用Redis v4推荐的实现方式
|
|
444
|
-
- 优化mget方法,直接使用Redis v4的mGet API
|
|
445
|
-
- 修复集合操作(srem)和有序集合操作(zadd/zrange/zscore/zrank)的兼容性问题
|
|
446
|
-
- 完善测试用例,确保所有功能正常工作
|
|
447
|
-
- 更新依赖版本,优化连接管理
|
|
448
|
-
- 完善事件系统,为incr、decr、incrby、decrby方法添加前置事件(_before)支持
|
|
449
|
-
- 确保所有非查询方法都有完整的_before、_after、_error事件触发机制
|
|
450
|
-
- 更新文档,添加新支持的事件到事件列表中
|
|
451
|
-
- 版本号更新和发布日期更新
|
|
452
|
-
|
|
453
|
-
### 1.8.1 (2024-10-09)
|
|
454
|
-
- 修复mget方法返回格式问题,确保与原生Redis保持一致
|
|
455
|
-
- 修复mset方法参数验证逻辑,优化批量设置功能
|
|
456
|
-
- 优化Pipeline实现,确保命令正确执行
|
|
457
|
-
- 修复连接池初始化和管理逻辑
|
|
458
|
-
- 修复存储机制,确保数据正确持久化
|
|
459
|
-
- 准备npm发布,优化文档格式和结构
|
|
460
|
-
- 添加npm徽章和下载统计
|
|
461
|
-
|
|
462
|
-
### 1.8.0 (2024-10-08)
|
|
463
|
-
- 新增集合(Set)操作支持:sadd、srem、sismember、smembers、scard、sinter、sunion、sdiff
|
|
464
|
-
- 新增有序集合(Sorted Set)操作支持:zadd、zrem、zscore、zrank、zrange、zcard、zincrby
|
|
465
|
-
- 新增数值操作支持:incr、decr、incrby、decrby、expire
|
|
466
|
-
- 更新文档,添加新功能的API说明
|
|
467
|
-
- 更新版本号和发布日期
|
|
468
|
-
|
|
469
|
-
### 1.7.0 (2024-10-07)
|
|
470
|
-
- 统一事件系统的属性命名规范
|
|
471
|
-
- 更新所有方法的事件emit属性,使用统一的key、value、ttl、result等命名
|
|
472
|
-
- 增加事件系统的详细文档
|
|
473
|
-
- 修复部分方法中的拼写错误
|
|
474
|
-
|
|
475
|
-
### 1.6.0 (2024-01-10)
|
|
476
|
-
- 添加完整的连接池管理功能
|
|
477
|
-
- 新增Pipeline批量操作优化
|
|
478
|
-
- 增加Hash数据类型支持
|
|
479
|
-
- 增强错误处理和日志记录
|
|
480
|
-
- 优化重连机制,实现指数退避策略
|
|
481
|
-
|
|
482
|
-
### 1.5.0
|
|
483
|
-
- 优化连接管理
|
|
484
|
-
- 完善错误处理
|
|
485
|
-
- 提升代码稳定性
|
|
431
|
+
### 2.0.0 (2025-10-14)
|
|
432
|
+
- 移除list_push方法,统一使用addForList方法进行列表添加操作
|
|
433
|
+
- 更新文档,将所有list_push引用替换为addForList
|
|
434
|
+
- 更新文档中的API列表和使用示例
|
|
435
|
+
- 优化连接池配置管理,统一配置到this.config.pool中
|
|
436
|
+
- 新增连接池配置参数:min_idle、max_idle、idle_timeout
|
|
486
437
|
|
|
487
438
|
## 贡献指南
|
|
488
439
|
|
package/index.js
CHANGED
|
@@ -1805,87 +1805,6 @@ Redis.prototype.setForList = async function(key, value, seconds) {
|
|
|
1805
1805
|
}
|
|
1806
1806
|
};
|
|
1807
1807
|
|
|
1808
|
-
/**
|
|
1809
|
-
* @description 数组缓存追加对象
|
|
1810
|
-
* @param {String} key 键
|
|
1811
|
-
* @param {Object|Array} value 值
|
|
1812
|
-
* @return {Promise<Number>} 追加后的数组长度
|
|
1813
|
-
*/
|
|
1814
|
-
Redis.prototype.list_push = async function(key, value) {
|
|
1815
|
-
try {
|
|
1816
|
-
// 触发前置事件,允许修改或阻止操作
|
|
1817
|
-
const beforeEventData = {
|
|
1818
|
-
key,
|
|
1819
|
-
value,
|
|
1820
|
-
cancel: false
|
|
1821
|
-
};
|
|
1822
|
-
this.emit('list_push_before', beforeEventData);
|
|
1823
|
-
|
|
1824
|
-
// 如果事件处理器标记为取消,则返回0
|
|
1825
|
-
if (beforeEventData.cancel) {
|
|
1826
|
-
$.log.debug(`[Redis] list_push操作被事件处理器取消 [${key}]`);
|
|
1827
|
-
return 0;
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
// 使用可能被修改的值
|
|
1831
|
-
let {
|
|
1832
|
-
key: finalKey,
|
|
1833
|
-
value: finalValue
|
|
1834
|
-
} = beforeEventData;
|
|
1835
|
-
let len = 0;
|
|
1836
|
-
let success = true;
|
|
1837
|
-
|
|
1838
|
-
const connection = await this._getConnection();
|
|
1839
|
-
try {
|
|
1840
|
-
finalKey = this.applyPrefix(finalKey);
|
|
1841
|
-
|
|
1842
|
-
if (Array.isArray(finalValue)) {
|
|
1843
|
-
// 添加数组元素
|
|
1844
|
-
if (typeof connection.rPush === 'function') {
|
|
1845
|
-
len = await connection.rPush(finalKey, finalValue);
|
|
1846
|
-
} else if (typeof connection.execute === 'function') {
|
|
1847
|
-
len = await connection.execute('RPUSH', [finalKey, ...finalValue]);
|
|
1848
|
-
} else {
|
|
1849
|
-
$.log.error('[Redis] 连接对象不支持rPush操作');
|
|
1850
|
-
success = false;
|
|
1851
|
-
len = 0;
|
|
1852
|
-
}
|
|
1853
|
-
} else {
|
|
1854
|
-
// 添加单个元素
|
|
1855
|
-
if (typeof connection.rPush === 'function') {
|
|
1856
|
-
len = await connection.rPush(finalKey, finalValue);
|
|
1857
|
-
} else if (typeof connection.execute === 'function') {
|
|
1858
|
-
len = await connection.execute('RPUSH', [finalKey, finalValue]);
|
|
1859
|
-
} else {
|
|
1860
|
-
$.log.error('[Redis] 连接对象不支持rPush操作');
|
|
1861
|
-
success = false;
|
|
1862
|
-
len = 0;
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
// 触发后置事件
|
|
1867
|
-
this.emit('list_push_after', {
|
|
1868
|
-
key: finalKey,
|
|
1869
|
-
value: finalValue,
|
|
1870
|
-
result: len,
|
|
1871
|
-
success
|
|
1872
|
-
});
|
|
1873
|
-
return len;
|
|
1874
|
-
} finally {
|
|
1875
|
-
this._recycleConnection(connection);
|
|
1876
|
-
}
|
|
1877
|
-
} catch (err) {
|
|
1878
|
-
// 触发错误事件
|
|
1879
|
-
this.emit('list_push_error', {
|
|
1880
|
-
key,
|
|
1881
|
-
value,
|
|
1882
|
-
error: err
|
|
1883
|
-
});
|
|
1884
|
-
$.log.error(`[Redis] 向列表追加元素失败 [${key}]:`, err);
|
|
1885
|
-
return 0;
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
|
|
1889
1808
|
/**
|
|
1890
1809
|
* @description 数组缓存追加对象
|
|
1891
1810
|
* @param {String} key 键
|