mm_redis 1.9.4 → 1.9.5

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.
@@ -0,0 +1,64 @@
1
+ ```markdown
2
+ # 三种缓存方式方法兼容性对比表格
3
+
4
+ ## 核心缓存方法
5
+
6
+ | 方法名 | Redis | MongoDB | CacheBase | 状态说明 |
7
+ |-------|-------|---------|-----------|----------|
8
+ | set | ✅ | ✅ | ✅ | 完全兼容 |
9
+ | get | ✅ | ✅ | ✅ | 完全兼容 |
10
+ | del | ✅ | ✅ | ✅ | 完全兼容 |
11
+ | has | ❌ | ✅ | ✅ | Redis无此方法,CacheBase保持兼容 |
12
+ | clear | ❌ | ✅ | ✅ | Redis无此方法,CacheBase保持兼容 |
13
+ | keys | ✅ | ✅ | ✅ | 完全兼容 |
14
+ | ttl | ✅ | ❌ | ✅ | Redis原生支持,CacheBase模拟实现 |
15
+ | persist | ✅ | ❌ | ✅ | Redis原生支持,CacheBase模拟实现 |
16
+ | add | ❌ | ✅ | ✅ | Redis无此方法,CacheBase保持兼容 |
17
+ | addInt | ❌ | ✅ | ✅ | Redis无此方法,CacheBase保持兼容 |
18
+ | addStr | ❌ | ✅ | ✅ | Redis无此方法,CacheBase保持兼容 |
19
+ | sort | ✅ | ❌ | ✅ | Redis原生支持,CacheBase模拟实现 |
20
+
21
+ ## Redis兼容方法 - 哈希表操作
22
+
23
+ | 方法名 | Redis | MongoDB | CacheBase | 状态说明 |
24
+ |-------|-------|---------|-----------|----------|
25
+ | hset | ✅ | ✅ | ✅ | 模拟实现,通过set对象方式 |
26
+ | hget | ✅ | ✅ | ✅ | 模拟实现,通过get对象方式 |
27
+ | hgetall | ✅ | ✅ | ✅ | 模拟实现,返回完整对象 |
28
+ | hdel | ✅ | ✅ | ✅ | 模拟实现,删除对象属性 |
29
+ | hexists | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
30
+ | hkeys | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
31
+ | hvals | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
32
+
33
+ ## Redis兼容方法 - 集合操作
34
+
35
+ | 方法名 | Redis | MongoDB | CacheBase | 状态说明 |
36
+ |-------|-------|---------|-----------|----------|
37
+ | sadd | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
38
+ | srem | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
39
+ | sismember | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
40
+ | smembers | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
41
+ | scard | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
42
+
43
+ ## Redis兼容方法 - 有序集合操作
44
+
45
+ | 方法名 | Redis | MongoDB | CacheBase | 状态说明 |
46
+ |-------|-------|---------|-----------|----------|
47
+ | zadd | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
48
+ | zrem | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
49
+ | zrange | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
50
+ | zscore | ✅ | ❌ | ❌ | Redis原生支持,CacheBase未实现 |
51
+
52
+ ## Redis兼容方法 - 其他常用命令
53
+
54
+ | 方法名 | Redis | MongoDB | CacheBase | 状态说明 |
55
+ |-------|-------|---------|-----------|----------|
56
+ | expire | ✅ | ❌ | ✅ | Redis原生支持,CacheBase通过ttl模拟 |
57
+ | incr | ✅ | ⚠️ | ✅ | Redis原生支持,MongoDB返回undefined,CacheBase通过addInt模拟 |
58
+ | decr | ✅ | ⚠️ | ✅ | Redis原生支持,MongoDB返回undefined,CacheBase通过addInt模拟 |
59
+ | exists | ✅ | ✅ | ✅ | 兼容,Redis原生支持 |
60
+ | mget | ✅ | ⚠️ | ✅ | Redis原生支持,CacheBase实现兼容 |
61
+ | mset | ✅ | ✅ | ✅ | Redis原生支持,CacheBase实现兼容 |
62
+
63
+ 注:✅ 完全兼容/功能正常 | ⚠️ 部分兼容/有异常 | ❌ 不兼容/未实现
64
+ ```
package/index.js CHANGED
@@ -632,7 +632,8 @@ Redis.prototype.addInt = async function (key, num) {
632
632
  // 触发错误事件
633
633
  this.emit('addInt_error', { key, value: num, error: err });
634
634
  $.log.error(`[Redis] 增加整数值失败 [${key}]:`, err);
635
- throw err;
635
+ // 与CacheBase保持一致,错误时返回默认值而不是抛出异常
636
+ return 0;
636
637
  }
637
638
  };
638
639
 
@@ -648,10 +649,10 @@ Redis.prototype.addFloat = async function (key, num) {
648
649
  const beforeEventData = { key, value: num, cancel: false };
649
650
  this.emit('addFloat_before', beforeEventData);
650
651
 
651
- // 如果事件处理器标记为取消,则抛出错误
652
+ // 如果事件处理器标记为取消,则返回默认值
652
653
  if (beforeEventData.cancel) {
653
654
  $.log.debug(`[Redis] addFloat操作被事件处理器取消 [${key}]`);
654
- throw new Error('addFloat操作被取消');
655
+ return 0;
655
656
  }
656
657
 
657
658
  // 使用可能被修改的值
@@ -707,7 +708,8 @@ Redis.prototype.addFloat = async function (key, num) {
707
708
  // 触发错误事件
708
709
  this.emit('addFloat_error', { key, value: num, error: err });
709
710
  $.log.error(`[Redis] 增加浮点数值失败 [${key}]:`, err);
710
- throw err;
711
+ // 与CacheBase保持一致,错误时返回默认值而不是抛出异常
712
+ return 0;
711
713
  }
712
714
  };
713
715
 
@@ -2054,7 +2056,7 @@ Redis.prototype._releaseConnection = function (connection) {
2054
2056
  } else {
2055
2057
  $.log.debug('[Redis] 连接对象没有可用的关闭方法');
2056
2058
  }
2057
- $.log.debug('[Redis] 关闭多余连接:', connection.id);
2059
+ // $.log.debug('[Redis] 关闭多余连接:', connection.id);
2058
2060
  } catch (e) {
2059
2061
  $.log.error('[Redis] 关闭多余连接失败:', e);
2060
2062
  }
@@ -2065,6 +2067,9 @@ Redis.prototype._releaseConnection = function (connection) {
2065
2067
  }
2066
2068
  };
2067
2069
 
2070
+ // 确保_recycleConnection方法是_releaseConnection的别名
2071
+ Redis.prototype._recycleConnection = Redis.prototype._releaseConnection;
2072
+
2068
2073
  // 添加Hash操作相关方法
2069
2074
 
2070
2075
  /**
@@ -2891,7 +2896,7 @@ Redis.prototype._createConnection = function () {
2891
2896
 
2892
2897
  // 连接Redis
2893
2898
  connection.connect().then(() => {
2894
- $.log.debug('[Redis] 新连接已创建并连接:', connection.id);
2899
+ // $.log.debug('[Redis] 新连接已创建并连接:', connection.id);
2895
2900
  resolve(connection);
2896
2901
  }).catch(err => {
2897
2902
  $.log.error('[Redis] 创建连接失败:', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_redis",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "高效的Redis客户端封装库,提供连接池管理、数据类型操作、错误处理和批量操作优化",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "homepage": "https://www.npmjs.com/package/mm_redis",
36
36
  "dependencies": {
37
37
  "mm_logs": "^1.5.2",
38
- "redis": "^4.7.0"
38
+ "redis": "^5.8.3"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=14.0.0"