mm_redis 2.0.9 → 2.1.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.
Files changed (3) hide show
  1. package/eslint.config.js +211 -0
  2. package/index.js +197 -200
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -8,38 +8,36 @@ const { Base } = require('mm_expand');
8
8
  * @description Redis缓存帮助类函数
9
9
  */
10
10
  class Redis extends Base {
11
+ static config = {
12
+ // 服务器地址
13
+ "host": "localhost",
14
+ // 端口号
15
+ "port": 6379,
16
+ // 密码
17
+ "password": "asd159357",
18
+ // 数据库
19
+ "database": 0,
20
+ // 前缀
21
+ "prefix": "",
22
+ // 连接超时时间(ms)
23
+ "connect_timeout": 10000,
24
+ // 重试次数
25
+ "retry_count": 3,
26
+ // 重试间隔(ms)
27
+ "retry_delay": 1000,
28
+ // 连接池配置
29
+ "max_clients": 100, // 最大连接数
30
+ "min_idle": 5, // 最小空闲连接数
31
+ "max_idle": 20, // 最大空闲连接数
32
+ "idle_timeout": 30000 // 空闲超时时间(ms)
33
+ };
11
34
  /**
12
35
  * @description 创建Redis帮助类函数 (构造函数)
13
36
  * @param {Object} config 配置参数
14
37
  * @constructor
15
38
  */
16
39
  constructor(config) {
17
- super();
18
- // 配置参数
19
- this.config = {
20
- // 服务器地址
21
- "host": "localhost",
22
- // 端口号
23
- "port": 6379,
24
- // 密码
25
- "password": "asd159357",
26
- // 数据库
27
- "database": 0,
28
- // 前缀
29
- "prefix": "",
30
- // 连接超时时间(ms)
31
- "connect_timeout": 10000,
32
- // 重试次数
33
- "retry_count": 3,
34
- // 重试间隔(ms)
35
- "retry_delay": 1000,
36
- // 连接池配置
37
- "max_clients": 100, // 最大连接数
38
- "min_idle": 5, // 最小空闲连接数
39
- "max_idle": 20, // 最大空闲连接数
40
- "idle_timeout": 30000 // 空闲超时时间(ms)
41
- };
42
- this.setConfig(config);
40
+ super(Redis.config);
43
41
  // 初始化连接池
44
42
  this._initPool();
45
43
  // 唯一标识符
@@ -52,6 +50,7 @@ class Redis extends Base {
52
50
  this.retry_count = 0;
53
51
  // 订阅回调函数
54
52
  this.func_list = {};
53
+ this.setConfig(config);
55
54
  }
56
55
  }
57
56
 
@@ -98,7 +97,7 @@ Redis.prototype.subscribe = async function (channel, func) {
98
97
  this.func_list[channel] = func;
99
98
  return true;
100
99
  } catch (err) {
101
- this.logger('error', `订阅频道 ${channel} 失败:`, err);
100
+ this.log('error', `订阅频道 ${channel} 失败:`, err);
102
101
  return false;
103
102
  }
104
103
  };
@@ -119,7 +118,7 @@ Redis.prototype.unsubscribe = async function (channel) {
119
118
  delete this.func_list[channel];
120
119
  return true;
121
120
  } catch (err) {
122
- this.logger('error', `取消订阅频道 ${channel} 失败:`, err);
121
+ this.log('error', `取消订阅频道 ${channel} 失败:`, err);
123
122
  return false;
124
123
  }
125
124
  };
@@ -142,7 +141,7 @@ Redis.prototype.publish = async function (channel, message) {
142
141
  try {
143
142
  return await this.conn.publish(this._addPrefix(channel), message);
144
143
  } catch (err) {
145
- this.logger('error', `发布消息到频道 ${channel} 失败:`, err);
144
+ this.log('error', `发布消息到频道 ${channel} 失败:`, err);
146
145
  return false;
147
146
  }
148
147
  };
@@ -154,7 +153,7 @@ Redis.prototype.publish = async function (channel, message) {
154
153
  */
155
154
  Redis.prototype.main = async function (channel, message) {
156
155
  // 默认实现,可由子类重写
157
- this.logger('debug', `收到未处理的消息 [${channel}]:`, message);
156
+ this.log('debug', `收到未处理的消息 [${channel}]:`, message);
158
157
  };
159
158
 
160
159
  /**
@@ -170,7 +169,7 @@ Redis.prototype.message = function (channel, message) {
170
169
  try {
171
170
  func(message);
172
171
  } catch (err) {
173
- this.logger('error', `处理频道 ${channel} 的消息时出错:`, err);
172
+ this.log('error', `处理频道 ${channel} 的消息时出错:`, err);
174
173
  }
175
174
  } else {
176
175
  this.main(channel, message);
@@ -194,7 +193,7 @@ Redis.prototype.setConfig = function (config) {
194
193
 
195
194
  // 初始化连接池
196
195
  this._initPool();
197
- // this.logger('debug','配置已更新');
196
+ // this.log('debug','配置已更新');
198
197
  this.identifier = this.config.host + "/" + this.config.database;
199
198
  return this;
200
199
  };
@@ -211,7 +210,7 @@ Redis.prototype._initPool = function () {
211
210
  };
212
211
 
213
212
  // 记录连接池初始化
214
- // this.logger('debug','连接池已初始化,配置:', this.config);
213
+ // this.log('debug','连接池已初始化,配置:', this.config);
215
214
  };
216
215
 
217
216
  /**
@@ -240,7 +239,7 @@ Redis.prototype.open = async function () {
240
239
 
241
240
  // 监听错误事件
242
241
  this.conn.on('error', (err) => {
243
- this.logger('error', 'Redis连接错误:', err);
242
+ this.log('error', 'Redis连接错误:', err);
244
243
  this.connected = false;
245
244
  // 尝试重连
246
245
  this._reconnect();
@@ -248,25 +247,25 @@ Redis.prototype.open = async function () {
248
247
 
249
248
  // 监听连接成功事件
250
249
  this.conn.on('connect', () => {
251
- // this.logger('debug','Redis已连接');
250
+ // this.log('debug','Redis已连接');
252
251
  this.connected = true;
253
252
  this.retry_count = 0;
254
253
  });
255
254
 
256
255
  // 监听断开连接事件
257
256
  this.conn.on('end', () => {
258
- // this.logger('debug','Redis连接已断开');
257
+ // this.log('debug','Redis连接已断开');
259
258
  this.connected = false;
260
259
  });
261
260
 
262
261
  // 监听订阅成功事件
263
262
  this.conn.on('subscribe', (channel, count) => {
264
- this.logger('debug', `频道${this._delPrefix(channel)}订阅成功, 当前总计订阅数:${count}`);
263
+ this.log('debug', `频道${this._delPrefix(channel)}订阅成功, 当前总计订阅数:${count}`);
265
264
  });
266
265
 
267
266
  // 监听取消订阅事件
268
267
  this.conn.on('unsubscribe', (channel, count) => {
269
- this.logger('debug', `频道${this._delPrefix(channel)}取消订阅, 当前总计订阅数:${count}`);
268
+ this.log('debug', `频道${this._delPrefix(channel)}取消订阅, 当前总计订阅数:${count}`);
270
269
  });
271
270
 
272
271
  // 收到消息后执行回调
@@ -279,7 +278,7 @@ Redis.prototype.open = async function () {
279
278
  this.connected = true;
280
279
  return true;
281
280
  } catch (err) {
282
- this.logger('error', 'Redis连接失败:', err);
281
+ this.log('error', 'Redis连接失败:', err);
283
282
  // 尝试重连
284
283
  this._reconnect();
285
284
  return false;
@@ -292,18 +291,18 @@ Redis.prototype.open = async function () {
292
291
  */
293
292
  Redis.prototype._reconnect = function () {
294
293
  if (this.retry_count >= this.config.retry_count) {
295
- this.logger('error', `达到最大重连次数 ${this.config.retry_count},停止重连`);
294
+ this.log('error', `达到最大重连次数 ${this.config.retry_count},停止重连`);
296
295
  return;
297
296
  }
298
297
 
299
298
  this.retry_count++;
300
- this.logger('debug', `尝试第 ${this.retry_count} 次重连...`);
299
+ this.log('debug', `尝试第 ${this.retry_count} 次重连...`);
301
300
 
302
301
  setTimeout(async () => {
303
302
  try {
304
303
  await this.open();
305
304
  } catch (err) {
306
- this.logger('error', `重连失败:`, err);
305
+ this.log('error', `重连失败:`, err);
307
306
  }
308
307
  }, this.config.retry_delay);
309
308
  };
@@ -315,7 +314,7 @@ Redis.prototype._reconnect = function () {
315
314
  // 修复close方法,正确处理连接池
316
315
  Redis.prototype.close = function () {
317
316
  try {
318
- // this.logger('debug','关闭所有连接...');
317
+ // this.log('debug','关闭所有连接...');
319
318
 
320
319
  // 关闭所有使用中的连接
321
320
  if (this.connection_pool && this.connection_pool.in_use) {
@@ -323,7 +322,7 @@ Redis.prototype.close = function () {
323
322
  try {
324
323
  connection.close();
325
324
  } catch (e) {
326
- this.logger('error', '关闭连接失败:', e);
325
+ this.log('error', '关闭连接失败:', e);
327
326
  }
328
327
  }
329
328
  this.connection_pool.in_use.clear();
@@ -340,20 +339,20 @@ Redis.prototype.close = function () {
340
339
  // 某些Redis客户端可能使用end方法
341
340
  connection.end();
342
341
  } else {
343
- this.logger('debug', '连接对象没有可用的关闭方法');
342
+ this.log('debug', '连接对象没有可用的关闭方法');
344
343
  }
345
344
  } catch (e) {
346
- this.logger('error', '关闭连接失败:', e);
345
+ this.log('error', '关闭连接失败:', e);
347
346
  }
348
347
  }
349
348
  this.connection_pool.available = [];
350
349
  }
351
350
 
352
351
  this.connected = false;
353
- this.logger('debug', 'Redis连接已断开');
352
+ this.log('debug', 'Redis连接已断开');
354
353
  return Promise.resolve(true);
355
354
  } catch (error) {
356
- this.logger('error', '关闭连接时发生错误:', error);
355
+ this.log('error', '关闭连接时发生错误:', error);
357
356
  return Promise.resolve(false);
358
357
  }
359
358
  };
@@ -480,7 +479,7 @@ Redis.prototype.pipeline = function () {
480
479
  // 直接返回结果值,符合测试期望的格式
481
480
  results.push(result);
482
481
  } catch (err) {
483
- this.logger('error', `Pipeline命令执行失败 [${cmd[0]}]:`, err);
482
+ this.log('error', `Pipeline命令执行失败 [${cmd[0]}]:`, err);
484
483
  results.push(null);
485
484
  }
486
485
  }
@@ -489,7 +488,7 @@ Redis.prototype.pipeline = function () {
489
488
  redisInstance._recycleConnection(connection);
490
489
  return results;
491
490
  } catch (error) {
492
- this.logger('error', 'Pipeline执行失败:', error);
491
+ this.log('error', 'Pipeline执行失败:', error);
493
492
  return [];
494
493
  }
495
494
  }
@@ -536,7 +535,7 @@ Redis.prototype.ttl = async function (key, seconds) {
536
535
  await connection.execute('EXPIRE', [key, seconds]);
537
536
  return true;
538
537
  } else {
539
- this.logger('error', '连接对象不支持expire操作');
538
+ this.log('error', '连接对象不支持expire操作');
540
539
  return false;
541
540
  }
542
541
  }
@@ -547,14 +546,14 @@ Redis.prototype.ttl = async function (key, seconds) {
547
546
  } else if (typeof connection.execute === 'function') {
548
547
  return await connection.execute('TTL', [key]);
549
548
  } else {
550
- this.logger('error', '连接对象不支持ttl操作');
549
+ this.log('error', '连接对象不支持ttl操作');
551
550
  return -2; // 默认返回键不存在
552
551
  }
553
552
  } finally {
554
553
  this._recycleConnection(connection);
555
554
  }
556
555
  } catch (err) {
557
- this.logger('error', `${seconds !== undefined ? '设置' : '获取'}过期时间失败 [${key}]:`, err);
556
+ this.log('error', `${seconds !== undefined ? '设置' : '获取'}过期时间失败 [${key}]:`, err);
558
557
  return seconds !== undefined ? false : -2;
559
558
  }
560
559
  };
@@ -588,7 +587,7 @@ Redis.prototype.addInt = async function (key, num, seconds = 0) {
588
587
 
589
588
  // 如果事件处理器标记为取消,则返回false
590
589
  if (ctx.cancel) {
591
- this.logger('debug', `addInt操作被事件处理器取消 [${key}]`);
590
+ this.log('debug', `addInt操作被事件处理器取消 [${key}]`);
592
591
  return false;
593
592
  }
594
593
 
@@ -611,7 +610,7 @@ Redis.prototype.addInt = async function (key, num, seconds = 0) {
611
610
  result = await connection.execute('INCRBY', [prefixedKey, finalNum]);
612
611
  } else {
613
612
  // 如果出错,回退到先获取再设置的方式
614
- this.logger('warn', `使用原子操作增加整数值失败,使用回退方案 [${key}]`);
613
+ this.log('warn', `使用原子操作增加整数值失败,使用回退方案 [${key}]`);
615
614
  let value = await this.get(prefixedKey);
616
615
  let n = 0;
617
616
  if (value) {
@@ -629,7 +628,7 @@ Redis.prototype.addInt = async function (key, num, seconds = 0) {
629
628
  result = await connection.execute('DECRBY', [prefixedKey, -finalNum]);
630
629
  } else {
631
630
  // 如果出错,回退到先获取再设置的方式
632
- this.logger('warn', `使用原子操作减少整数值失败,使用回退方案`);
631
+ this.log('warn', `使用原子操作减少整数值失败,使用回退方案`);
633
632
  let value = await this.get(prefixedKey);
634
633
  let n = 0;
635
634
  if (value) {
@@ -670,7 +669,7 @@ Redis.prototype.addInt = async function (key, num, seconds = 0) {
670
669
  seconds,
671
670
  error: err
672
671
  });
673
- this.logger('error', `增加整数值失败 [${key}]:`, err);
672
+ this.log('error', `增加整数值失败 [${key}]:`, err);
674
673
  // 与CacheBase保持一致,错误时返回默认值而不是抛出异常
675
674
  return 0;
676
675
  }
@@ -708,7 +707,7 @@ Redis.prototype.addFloat = async function (key, num, seconds = 0) {
708
707
 
709
708
  // 如果事件处理器标记为取消,则返回默认值
710
709
  if (ctx.cancel) {
711
- this.logger('debug', `addFloat操作被事件处理器取消 [${key}]`);
710
+ this.log('debug', `addFloat操作被事件处理器取消 [${key}]`);
712
711
  return 0;
713
712
  }
714
713
 
@@ -734,7 +733,7 @@ Redis.prototype.addFloat = async function (key, num, seconds = 0) {
734
733
  }
735
734
  // 回退方案
736
735
  else {
737
- this.logger('warn', `连接对象不支持incrByFloat操作,使用回退方案`);
736
+ this.log('warn', `连接对象不支持incrByFloat操作,使用回退方案`);
738
737
  let value = await this.get(prefixedKey);
739
738
  let n = 0;
740
739
  if (value) {
@@ -765,7 +764,7 @@ Redis.prototype.addFloat = async function (key, num, seconds = 0) {
765
764
  return result;
766
765
  } catch (err) {
767
766
  // 如果出错,回退到先获取再设置的方式
768
- this.logger('warn', `使用原子操作增加浮点数值失败,使用回退方案:`, err);
767
+ this.log('warn', `使用原子操作增加浮点数值失败,使用回退方案:`, err);
769
768
  let value = await this.get(prefixedKey);
770
769
  let n = 0;
771
770
  if (value) {
@@ -794,7 +793,7 @@ Redis.prototype.addFloat = async function (key, num, seconds = 0) {
794
793
  seconds,
795
794
  error: err
796
795
  });
797
- this.logger('error', `增加浮点数值失败 [${key}]:`, err);
796
+ this.log('error', `增加浮点数值失败 [${key}]:`, err);
798
797
  // 与CacheBase保持一致,错误时返回默认值而不是抛出异常
799
798
  return 0;
800
799
  }
@@ -831,7 +830,7 @@ Redis.prototype.addStr = async function (key, str, seconds = 0) {
831
830
 
832
831
  // 如果事件处理器标记为取消,则返回0
833
832
  if (ctx.cancel) {
834
- this.logger('debug', `addStr操作被事件处理器取消 [${key}]`);
833
+ this.log('debug', `addStr操作被事件处理器取消 [${key}]`);
835
834
  return 0;
836
835
  }
837
836
 
@@ -857,7 +856,7 @@ Redis.prototype.addStr = async function (key, str, seconds = 0) {
857
856
  }
858
857
  // 回退方案
859
858
  else {
860
- this.logger('warn', `连接对象不支持append操作,使用回退方案`);
859
+ this.log('warn', `连接对象不支持append操作,使用回退方案`);
861
860
  let value = await this.get(prefixedKey) || '';
862
861
  value += finalStr;
863
862
  await this.set(prefixedKey, value, finalSeconds);
@@ -883,7 +882,7 @@ Redis.prototype.addStr = async function (key, str, seconds = 0) {
883
882
  });
884
883
  return result;
885
884
  } catch (err) {
886
- this.logger('warn', '追加字符串失败:', err);
885
+ this.log('warn', '追加字符串失败:', err);
887
886
  // 回退方案:先获取再设置
888
887
  let value = await this.get(prefixedKey) || '';
889
888
  value += finalStr;
@@ -909,7 +908,7 @@ Redis.prototype.addStr = async function (key, str, seconds = 0) {
909
908
  seconds,
910
909
  error: err
911
910
  });
912
- this.logger('error', `追加字符串失败 [${key}]:`, err);
911
+ this.log('error', `追加字符串失败 [${key}]:`, err);
913
912
  return 0;
914
913
  }
915
914
  };
@@ -952,7 +951,7 @@ Redis.prototype.del = async function (key) {
952
951
 
953
952
  // 如果事件处理器标记为取消,则返回false
954
953
  if (ctx.cancel) {
955
- this.logger('debug', `del操作被事件处理器取消 [${key}]`);
954
+ this.log('debug', `del操作被事件处理器取消 [${key}]`);
956
955
  return false;
957
956
  }
958
957
 
@@ -1005,7 +1004,7 @@ Redis.prototype.del = async function (key) {
1005
1004
  key,
1006
1005
  error: err
1007
1006
  });
1008
- this.logger('error', `删除缓存失败 [${key}]:`, err);
1007
+ this.log('error', `删除缓存失败 [${key}]:`, err);
1009
1008
  return false;
1010
1009
  }
1011
1010
  };
@@ -1042,7 +1041,7 @@ Redis.prototype.set = async function (key, value, seconds = 0) {
1042
1041
 
1043
1042
  // 如果事件处理器标记为取消,则返回false
1044
1043
  if (ctx.cancel) {
1045
- this.logger('debug', `set操作被事件处理器取消 [${key}]`);
1044
+ this.log('debug', `set操作被事件处理器取消 [${key}]`);
1046
1045
  return false;
1047
1046
  }
1048
1047
 
@@ -1080,7 +1079,7 @@ Redis.prototype.set = async function (key, value, seconds = 0) {
1080
1079
  this._recycleConnection(connection);
1081
1080
  }
1082
1081
  } catch (err) {
1083
- this.logger('error', `设置缓存失败 [${key}]:`, err);
1082
+ this.log('error', `设置缓存失败 [${key}]:`, err);
1084
1083
  // 触发错误事件
1085
1084
  this.emit('set:error', {
1086
1085
  key,
@@ -1120,7 +1119,7 @@ Redis.prototype.add = async function (key, value, seconds) {
1120
1119
 
1121
1120
  // 如果事件处理器标记为取消,则返回false
1122
1121
  if (ctx.cancel) {
1123
- this.logger('debug', `add操作被事件处理器取消 [${key}]`);
1122
+ this.log('debug', `add操作被事件处理器取消 [${key}]`);
1124
1123
  return false;
1125
1124
  }
1126
1125
 
@@ -1160,7 +1159,7 @@ Redis.prototype.add = async function (key, value, seconds) {
1160
1159
  this._recycleConnection(connection);
1161
1160
  }
1162
1161
  } catch (err) {
1163
- this.logger('error', `添加缓存失败 [${key}]:`, err);
1162
+ this.log('error', `添加缓存失败 [${key}]:`, err);
1164
1163
  // 触发错误事件
1165
1164
  this.emit('add:error', {
1166
1165
  key,
@@ -1198,7 +1197,7 @@ Redis.prototype.get = async function (key) {
1198
1197
 
1199
1198
  // 如果事件处理器标记为取消,则返回null
1200
1199
  if (ctx.cancel) {
1201
- this.logger('debug', `get操作被事件处理器取消 [${key}]`);
1200
+ this.log('debug', `get操作被事件处理器取消 [${key}]`);
1202
1201
  return null;
1203
1202
  }
1204
1203
 
@@ -1239,7 +1238,7 @@ Redis.prototype.get = async function (key) {
1239
1238
  key,
1240
1239
  error: err
1241
1240
  });
1242
- this.logger('error', `获取缓存失败 [${key}]:`, err);
1241
+ this.log('error', `获取缓存失败 [${key}]:`, err);
1243
1242
  return null;
1244
1243
  }
1245
1244
  };
@@ -1265,7 +1264,7 @@ Redis.prototype.has = async function (key) {
1265
1264
 
1266
1265
  // 如果事件处理器标记为取消,则返回false
1267
1266
  if (ctx.cancel) {
1268
- this.logger('debug', `has操作被事件处理器取消 [${key}]`);
1267
+ this.log('debug', `has操作被事件处理器取消 [${key}]`);
1269
1268
  return false;
1270
1269
  }
1271
1270
 
@@ -1295,7 +1294,7 @@ Redis.prototype.has = async function (key) {
1295
1294
  key,
1296
1295
  error: err
1297
1296
  });
1298
- this.logger('error', `检查键是否存在失败 [${key}]:`, err);
1297
+ this.log('error', `检查键是否存在失败 [${key}]:`, err);
1299
1298
  return false;
1300
1299
  }
1301
1300
  };
@@ -1338,7 +1337,7 @@ Redis.prototype.exists = async function (key) {
1338
1337
 
1339
1338
  // 如果事件处理器标记为取消,则返回0
1340
1339
  if (ctx.cancel) {
1341
- this.logger('debug', `exists操作被事件处理器取消 [${key}]`);
1340
+ this.log('debug', `exists操作被事件处理器取消 [${key}]`);
1342
1341
  return 0;
1343
1342
  }
1344
1343
 
@@ -1373,7 +1372,7 @@ Redis.prototype.exists = async function (key) {
1373
1372
  key,
1374
1373
  error: err
1375
1374
  });
1376
- this.logger('error', `检查键存在性失败 [${key}]:`, err);
1375
+ this.log('error', `检查键存在性失败 [${key}]:`, err);
1377
1376
  return 0;
1378
1377
  }
1379
1378
  };
@@ -1392,7 +1391,7 @@ Redis.prototype.getrange = async function (key, start, end) {
1392
1391
  key = this._addPrefix(key);
1393
1392
  return await connection.getRange(key, start, end);
1394
1393
  } catch (err) {
1395
- this.logger('error', '获取字符串范围失败:', err);
1394
+ this.log('error', '获取字符串范围失败:', err);
1396
1395
  // 回退方案
1397
1396
  const value = await this.get(key);
1398
1397
  if (value && typeof value === 'string') {
@@ -1403,7 +1402,7 @@ Redis.prototype.getrange = async function (key, start, end) {
1403
1402
  this._recycleConnection(connection);
1404
1403
  }
1405
1404
  } catch (err) {
1406
- this.logger('error', `获取字符串范围失败 [${key}]:`, err);
1405
+ this.log('error', `获取字符串范围失败 [${key}]:`, err);
1407
1406
  return '';
1408
1407
  }
1409
1408
  };
@@ -1439,7 +1438,7 @@ Redis.prototype.setrange = async function (key, index, value) {
1439
1438
 
1440
1439
  // 如果事件处理器标记为取消,则返回0
1441
1440
  if (ctx.cancel) {
1442
- this.logger('debug', `setrange操作被事件处理器取消 [${key}]`);
1441
+ this.log('debug', `setrange操作被事件处理器取消 [${key}]`);
1443
1442
  return 0;
1444
1443
  }
1445
1444
 
@@ -1465,7 +1464,7 @@ Redis.prototype.setrange = async function (key, index, value) {
1465
1464
  }
1466
1465
  // 回退方案
1467
1466
  else {
1468
- this.logger('warn', `连接对象不支持setRange操作,使用回退方案`);
1467
+ this.log('warn', `连接对象不支持setRange操作,使用回退方案`);
1469
1468
  let str = await this.get(finalKey) || '';
1470
1469
  if (str.length < finalIndex) {
1471
1470
  // 填充空格到指定索引
@@ -1486,7 +1485,7 @@ Redis.prototype.setrange = async function (key, index, value) {
1486
1485
  });
1487
1486
  return result;
1488
1487
  } catch (err) {
1489
- this.logger('error', '设置字符串范围失败:', err);
1488
+ this.log('error', '设置字符串范围失败:', err);
1490
1489
  // 回退方案
1491
1490
  let str = await this.get(finalKey) || '';
1492
1491
  if (str.length < finalIndex) {
@@ -1516,7 +1515,7 @@ Redis.prototype.setrange = async function (key, index, value) {
1516
1515
  value,
1517
1516
  error: err
1518
1517
  });
1519
- this.logger('error', `设置字符串范围失败 [${key}]:`, err);
1518
+ this.log('error', `设置字符串范围失败 [${key}]:`, err);
1520
1519
  return 0;
1521
1520
  }
1522
1521
  };
@@ -1537,7 +1536,7 @@ Redis.prototype.clear = async function (key) {
1537
1536
 
1538
1537
  // 如果事件处理器标记为取消,则返回false
1539
1538
  if (ctx.cancel) {
1540
- this.logger('debug', `clear操作被事件处理器取消`);
1539
+ this.log('debug', `clear操作被事件处理器取消`);
1541
1540
  return false;
1542
1541
  }
1543
1542
 
@@ -1561,7 +1560,7 @@ Redis.prototype.clear = async function (key) {
1561
1560
  await connection.execute('FLUSHDB');
1562
1561
  success = true;
1563
1562
  } else {
1564
- this.logger('error', '连接对象不支持flushDb操作');
1563
+ this.log('error', '连接对象不支持flushDb操作');
1565
1564
  success = false;
1566
1565
  }
1567
1566
  }
@@ -1581,7 +1580,7 @@ Redis.prototype.clear = async function (key) {
1581
1580
  key,
1582
1581
  error: err
1583
1582
  });
1584
- this.logger('error', '清空缓存失败:', err);
1583
+ this.log('error', '清空缓存失败:', err);
1585
1584
  return false;
1586
1585
  }
1587
1586
  };
@@ -1625,7 +1624,7 @@ Redis.prototype.sort = async function (key, options = {}) {
1625
1624
 
1626
1625
  return await connection.sort(key, sortOptions);
1627
1626
  } catch (err) {
1628
- this.logger('error', '排序失败:', err);
1627
+ this.log('error', '排序失败:', err);
1629
1628
  // 回退方案:获取数据后在内存中排序
1630
1629
  const data = await this.getForList(key);
1631
1630
  return data.sort((a, b) => {
@@ -1639,7 +1638,7 @@ Redis.prototype.sort = async function (key, options = {}) {
1639
1638
  this._recycleConnection(connection);
1640
1639
  }
1641
1640
  } catch (err) {
1642
- this.logger('error', `排序失败 [${key}]:`, err);
1641
+ this.log('error', `排序失败 [${key}]:`, err);
1643
1642
  return [];
1644
1643
  }
1645
1644
  };
@@ -1662,7 +1661,7 @@ Redis.prototype.keys = async function (pattern = '*') {
1662
1661
  this._recycleConnection(connection);
1663
1662
  }
1664
1663
  } catch (err) {
1665
- this.logger('error', '获取键列表失败:', err);
1664
+ this.log('error', '获取键列表失败:', err);
1666
1665
  return [];
1667
1666
  }
1668
1667
  };
@@ -1687,7 +1686,7 @@ Redis.prototype.setForList = async function (key, value, seconds) {
1687
1686
 
1688
1687
  // 如果事件处理器标记为取消,则返回0
1689
1688
  if (ctx.cancel) {
1690
- this.logger('debug', `setForList操作被事件处理器取消 [${key}]`);
1689
+ this.log('debug', `setForList操作被事件处理器取消 [${key}]`);
1691
1690
  return 0;
1692
1691
  }
1693
1692
 
@@ -1717,7 +1716,7 @@ Redis.prototype.setForList = async function (key, value, seconds) {
1717
1716
  } else if (typeof connection.execute === 'function') {
1718
1717
  len = await connection.execute('RPUSH', [finalKey, ...finalValue]);
1719
1718
  } else {
1720
- this.logger('error', '连接对象不支持rPush操作');
1719
+ this.log('error', '连接对象不支持rPush操作');
1721
1720
  len = 0;
1722
1721
  }
1723
1722
  }
@@ -1728,7 +1727,7 @@ Redis.prototype.setForList = async function (key, value, seconds) {
1728
1727
  } else if (typeof connection.execute === 'function') {
1729
1728
  len = await connection.execute('RPUSH', [finalKey, finalValue]);
1730
1729
  } else {
1731
- this.logger('error', '连接对象不支持rPush操作');
1730
+ this.log('error', '连接对象不支持rPush操作');
1732
1731
  len = 0;
1733
1732
  }
1734
1733
  }
@@ -1739,7 +1738,7 @@ Redis.prototype.setForList = async function (key, value, seconds) {
1739
1738
  } else if (typeof connection.execute === 'function') {
1740
1739
  await connection.execute('EXPIRE', [finalKey, finalSeconds]);
1741
1740
  } else {
1742
- this.logger('error', '连接对象不支持expire操作');
1741
+ this.log('error', '连接对象不支持expire操作');
1743
1742
  }
1744
1743
  }
1745
1744
 
@@ -1762,7 +1761,7 @@ Redis.prototype.setForList = async function (key, value, seconds) {
1762
1761
  value,
1763
1762
  error: err
1764
1763
  });
1765
- this.logger('error', `设置列表失败 [${key}]:`, err);
1764
+ this.log('error', `设置列表失败 [${key}]:`, err);
1766
1765
  return 0;
1767
1766
  }
1768
1767
  };
@@ -1787,7 +1786,7 @@ Redis.prototype.addForList = async function (key, value, seconds = 0) {
1787
1786
 
1788
1787
  // 如果事件处理器标记为取消,则返回0
1789
1788
  if (ctx.cancel) {
1790
- this.logger('debug', `addForList操作被事件处理器取消 [${key}]`);
1789
+ this.log('debug', `addForList操作被事件处理器取消 [${key}]`);
1791
1790
  return 0;
1792
1791
  }
1793
1792
 
@@ -1811,7 +1810,7 @@ Redis.prototype.addForList = async function (key, value, seconds = 0) {
1811
1810
  } else if (typeof connection.execute === 'function') {
1812
1811
  len = await connection.execute('RPUSH', [finalKey, ...finalValue]);
1813
1812
  } else {
1814
- this.logger('error', '连接对象不支持rPush操作');
1813
+ this.log('error', '连接对象不支持rPush操作');
1815
1814
  len = 0;
1816
1815
  }
1817
1816
  }
@@ -1822,7 +1821,7 @@ Redis.prototype.addForList = async function (key, value, seconds = 0) {
1822
1821
  } else if (typeof connection.execute === 'function') {
1823
1822
  len = await connection.execute('RPUSH', [finalKey, finalValue]);
1824
1823
  } else {
1825
- this.logger('error', '连接对象不支持rPush操作');
1824
+ this.log('error', '连接对象不支持rPush操作');
1826
1825
  len = 0;
1827
1826
  }
1828
1827
  }
@@ -1833,7 +1832,7 @@ Redis.prototype.addForList = async function (key, value, seconds = 0) {
1833
1832
  } else if (typeof connection.execute === 'function') {
1834
1833
  await connection.execute('EXPIRE', [finalKey, finalSeconds]);
1835
1834
  } else {
1836
- this.logger('error', '连接对象不支持expire操作');
1835
+ this.log('error', '连接对象不支持expire操作');
1837
1836
  }
1838
1837
  }
1839
1838
 
@@ -1856,7 +1855,7 @@ Redis.prototype.addForList = async function (key, value, seconds = 0) {
1856
1855
  value,
1857
1856
  error: err
1858
1857
  });
1859
- this.logger('error', `添加列表项失败 [${key}]:`, err);
1858
+ this.log('error', `添加列表项失败 [${key}]:`, err);
1860
1859
  return 0;
1861
1860
  }
1862
1861
  };
@@ -1884,7 +1883,7 @@ Redis.prototype.hasForList = async function (key, value) {
1884
1883
  return itemStr === valueStr || item === value;
1885
1884
  });
1886
1885
  } catch (err) {
1887
- this.logger('error', `检查列表成员是否存在失败 [${key}]:`, err);
1886
+ this.log('error', `检查列表成员是否存在失败 [${key}]:`, err);
1888
1887
  return false;
1889
1888
  }
1890
1889
  };
@@ -1909,7 +1908,7 @@ Redis.prototype.getForList = async function (key, start = 0, end = -1) {
1909
1908
 
1910
1909
  // 如果事件处理器标记为取消,则返回空数组
1911
1910
  if (ctx.cancel) {
1912
- this.logger('debug', `getForList操作被事件处理器取消 [${key}]`);
1911
+ this.log('debug', `getForList操作被事件处理器取消 [${key}]`);
1913
1912
  return [];
1914
1913
  }
1915
1914
 
@@ -1934,12 +1933,12 @@ Redis.prototype.getForList = async function (key, start = 0, end = -1) {
1934
1933
  // 回退到通用execute方法
1935
1934
  result = await connection.execute('LRANGE', [finalKey, finalStart, finalEnd]);
1936
1935
  } else {
1937
- this.logger('error', '连接对象不支持lRange或lrange操作');
1936
+ this.log('error', '连接对象不支持lRange或lrange操作');
1938
1937
  return [];
1939
1938
  }
1940
1939
  // 确保结果是数组
1941
1940
  if (!Array.isArray(result)) {
1942
- this.logger('error', '列表查询结果不是数组格式');
1941
+ this.log('error', '列表查询结果不是数组格式');
1943
1942
  return [];
1944
1943
  }
1945
1944
 
@@ -1979,7 +1978,7 @@ Redis.prototype.getForList = async function (key, start = 0, end = -1) {
1979
1978
  end,
1980
1979
  error: err
1981
1980
  });
1982
- this.logger('error', `获取列表失败 [${key}]:`, err);
1981
+ this.log('error', `获取列表失败 [${key}]:`, err);
1983
1982
  return [];
1984
1983
  }
1985
1984
  };
@@ -2004,7 +2003,7 @@ Redis.prototype.clearForList = async function (key) {
2004
2003
 
2005
2004
  // 如果事件处理器标记为取消,则返回false
2006
2005
  if (ctx.cancel) {
2007
- this.logger('debug', `clearForList操作被事件处理器取消 [${key}]`);
2006
+ this.log('debug', `clearForList操作被事件处理器取消 [${key}]`);
2008
2007
  return false;
2009
2008
  }
2010
2009
 
@@ -2028,7 +2027,7 @@ Redis.prototype.clearForList = async function (key) {
2028
2027
  key,
2029
2028
  error: err
2030
2029
  });
2031
- this.logger('error', `清空列表失败 [${key}]:`, err);
2030
+ this.log('error', `清空列表失败 [${key}]:`, err);
2032
2031
  return false;
2033
2032
  }
2034
2033
  };
@@ -2066,7 +2065,7 @@ Redis.prototype.mget = async function (keys) {
2066
2065
 
2067
2066
  // 如果事件处理器标记为取消,则返回空数组
2068
2067
  if (ctx.cancel) {
2069
- this.logger('debug', `mget操作被事件处理器取消 [${keys}]`);
2068
+ this.log('debug', `mget操作被事件处理器取消 [${keys}]`);
2070
2069
  return [];
2071
2070
  }
2072
2071
 
@@ -2112,7 +2111,7 @@ Redis.prototype.mget = async function (keys) {
2112
2111
  keys,
2113
2112
  error: err
2114
2113
  });
2115
- this.logger('error', `批量获取缓存失败 [${keys}]:`, err);
2114
+ this.log('error', `批量获取缓存失败 [${keys}]:`, err);
2116
2115
  return [];
2117
2116
  }
2118
2117
  }
@@ -2135,7 +2134,7 @@ Redis.prototype.mset = async function (obj, seconds = 0) {
2135
2134
 
2136
2135
  // 如果事件处理器标记为取消,则返回false
2137
2136
  if (ctx.cancel) {
2138
- this.logger('debug', `mset操作被事件处理器取消`);
2137
+ this.log('debug', `mset操作被事件处理器取消`);
2139
2138
  return false;
2140
2139
  }
2141
2140
 
@@ -2181,7 +2180,7 @@ Redis.prototype.mset = async function (obj, seconds = 0) {
2181
2180
  });
2182
2181
 
2183
2182
  // 如果Pipeline失败,回退到原实现
2184
- this.logger('warn', '使用Pipeline批量设置失败,使用回退方案:', err);
2183
+ this.log('warn', '使用Pipeline批量设置失败,使用回退方案:', err);
2185
2184
  const connection = await this._getConnection();
2186
2185
  try {
2187
2186
  const pairs = [];
@@ -2219,7 +2218,7 @@ Redis.prototype.mset = async function (obj, seconds = 0) {
2219
2218
  seconds,
2220
2219
  error: fallbackErr
2221
2220
  });
2222
- this.logger('error', '回退方案批量设置也失败:', fallbackErr);
2221
+ this.log('error', '回退方案批量设置也失败:', fallbackErr);
2223
2222
  return false;
2224
2223
  } finally {
2225
2224
  this._recycleConnection(connection);
@@ -2250,7 +2249,7 @@ Redis.prototype.hdel = async function (key, fields) {
2250
2249
 
2251
2250
  // 如果事件处理器标记为取消,则返回false
2252
2251
  if (ctx.cancel) {
2253
- this.logger('debug', `hdel操作被事件处理器取消 [${key}]`);
2252
+ this.log('debug', `hdel操作被事件处理器取消 [${key}]`);
2254
2253
  return false;
2255
2254
  }
2256
2255
 
@@ -2275,7 +2274,7 @@ Redis.prototype.hdel = async function (key, fields) {
2275
2274
  } else if (typeof connection.execute === 'function') {
2276
2275
  deletedCount = await connection.execute('HDEL', [finalKey, ...finalFields]);
2277
2276
  } else {
2278
- this.logger('error', '连接对象不支持hDel操作');
2277
+ this.log('error', '连接对象不支持hDel操作');
2279
2278
  deletedCount = 0;
2280
2279
  }
2281
2280
 
@@ -2296,7 +2295,7 @@ Redis.prototype.hdel = async function (key, fields) {
2296
2295
  value: fields,
2297
2296
  error: err
2298
2297
  });
2299
- this.logger('error', `删除哈希字段失败 [${key}]:`, err);
2298
+ this.log('error', `删除哈希字段失败 [${key}]:`, err);
2300
2299
  return 0; // 与Redis语义保持一致,返回删除的字段数量
2301
2300
  }
2302
2301
  };
@@ -2316,7 +2315,7 @@ Redis.prototype.hlen = async function (key) {
2316
2315
  this._recycleConnection(connection);
2317
2316
  }
2318
2317
  } catch (err) {
2319
- this.logger('error', `获取哈希字段数量失败 [${key}]:`, err);
2318
+ this.log('error', `获取哈希字段数量失败 [${key}]:`, err);
2320
2319
  return 0;
2321
2320
  }
2322
2321
  };
@@ -2430,7 +2429,7 @@ class RedisPipeline {
2430
2429
  // 处理结果(解析JSON等)
2431
2430
  return results.map(([err, value], index) => {
2432
2431
  if (err) {
2433
- this.logger('error', `[Pipeline] Pipeline命令执行失败 [${this.commands[index].name}]:`, err);
2432
+ this.log('error', `[Pipeline] Pipeline命令执行失败 [${this.commands[index].name}]:`, err);
2434
2433
  return null;
2435
2434
  }
2436
2435
 
@@ -2470,7 +2469,7 @@ Redis.prototype.clearExpire = async function () {
2470
2469
  this.emit('clearExpire:error', {
2471
2470
  error: err
2472
2471
  });
2473
- this.logger('error', '清空过期数据失败:', err);
2472
+ this.log('error', '清空过期数据失败:', err);
2474
2473
  return false;
2475
2474
  }
2476
2475
  };
@@ -2499,14 +2498,14 @@ Redis.prototype._getConnection = function () {
2499
2498
  } else {
2500
2499
  // 否则等待连接释放
2501
2500
  // 这里简化处理,直接创建连接(生产环境应实现等待队列)
2502
- this.logger('warn', '连接池已满,创建额外连接');
2501
+ this.log('warn', '连接池已满,创建额外连接');
2503
2502
  this._createConnection().then(connection => {
2504
2503
  this.connection_pool.in_use.add(connection);
2505
2504
  resolve(connection);
2506
2505
  }).catch(reject);
2507
2506
  }
2508
2507
  } catch (error) {
2509
- this.logger('error', '获取连接失败:', error);
2508
+ this.log('error', '获取连接失败:', error);
2510
2509
  reject(error);
2511
2510
  }
2512
2511
  });
@@ -2529,15 +2528,15 @@ Redis.prototype._releaseConnection = function (connection) {
2529
2528
  } else if (typeof connection.end === 'function') {
2530
2529
  connection.end();
2531
2530
  } else {
2532
- this.logger('debug', '连接对象没有可用的关闭方法');
2531
+ this.log('debug', '连接对象没有可用的关闭方法');
2533
2532
  }
2534
2533
  } catch (e) {
2535
- this.logger('error', '关闭多余连接失败:', e);
2534
+ this.log('error', '关闭多余连接失败:', e);
2536
2535
  }
2537
2536
  }
2538
2537
  }
2539
2538
  } catch (error) {
2540
- this.logger('error', '释放连接失败:', error);
2539
+ this.log('error', '释放连接失败:', error);
2541
2540
  }
2542
2541
  };
2543
2542
 
@@ -2566,7 +2565,7 @@ Redis.prototype.hset = async function (key, field, value) {
2566
2565
 
2567
2566
  // 如果事件处理器标记为取消,则返回false
2568
2567
  if (ctx.cancel) {
2569
- this.logger('debug', `hset操作被事件处理器取消 [${key}:${field}]`);
2568
+ this.log('debug', `hset操作被事件处理器取消 [${key}:${field}]`);
2570
2569
  return false;
2571
2570
  }
2572
2571
 
@@ -2599,7 +2598,7 @@ Redis.prototype.hset = async function (key, field, value) {
2599
2598
  this._recycleConnection(connection);
2600
2599
  }
2601
2600
  } catch (err) {
2602
- this.logger('error', `设置哈希字段失败 [${key}:${field}]:`, err);
2601
+ this.log('error', `设置哈希字段失败 [${key}:${field}]:`, err);
2603
2602
  // 触发错误事件
2604
2603
  this.emit('hset:error', {
2605
2604
  key,
@@ -2641,7 +2640,7 @@ Redis.prototype.hget = async function (key, field) {
2641
2640
  this._recycleConnection(connection);
2642
2641
  }
2643
2642
  } catch (err) {
2644
- this.logger('error', `获取哈希字段失败 [${key}:${field}]:`, err);
2643
+ this.log('error', `获取哈希字段失败 [${key}:${field}]:`, err);
2645
2644
  return null;
2646
2645
  }
2647
2646
  };
@@ -2664,7 +2663,7 @@ Redis.prototype.hmset = async function (key, obj) {
2664
2663
 
2665
2664
  // 如果事件处理器标记为取消,则返回false
2666
2665
  if (ctx.cancel) {
2667
- this.logger('debug', `hmset操作被事件处理器取消 [${key}]`);
2666
+ this.log('debug', `hmset操作被事件处理器取消 [${key}]`);
2668
2667
  return false;
2669
2668
  }
2670
2669
 
@@ -2679,20 +2678,20 @@ Redis.prototype.hmset = async function (key, obj) {
2679
2678
  finalKey = this._addPrefix(finalKey);
2680
2679
 
2681
2680
  // 检查Redis版本,支持不同的方法
2682
- this.logger('debug',
2681
+ this.log('debug',
2683
2682
  `hmset方法检测到连接对象方法: hSet=${typeof connection.hSet === 'function'}, hmset=${typeof connection.hmset === 'function'}`
2684
2683
  );
2685
2684
  let success = true;
2686
2685
 
2687
2686
  // 优化策略:对所有Redis版本都使用逐个字段设置的方式,确保兼容性和正确性
2688
- this.logger('debug', `对键 ${finalKey} 强制使用逐个字段设置策略`);
2687
+ this.log('debug', `对键 ${finalKey} 强制使用逐个字段设置策略`);
2689
2688
 
2690
2689
  // 获取适合的设置字段方法
2691
2690
  const setFieldMethod = typeof connection.hSet === 'function' ? 'hSet' :
2692
2691
  typeof connection.hset === 'function' ? 'hset' : null;
2693
2692
 
2694
2693
  if (!setFieldMethod) {
2695
- this.logger('error', `连接对象不支持hSet或hset操作`);
2694
+ this.log('error', `连接对象不支持hSet或hset操作`);
2696
2695
  return false;
2697
2696
  }
2698
2697
 
@@ -2704,10 +2703,10 @@ Redis.prototype.hmset = async function (key, obj) {
2704
2703
  if (typeof value !== 'string') {
2705
2704
  value = JSON.stringify(value);
2706
2705
  }
2707
- this.logger('debug', `单独设置字段: ${setFieldMethod}(${finalKey}, ${field}, ${value})`);
2706
+ this.log('debug', `单独设置字段: ${setFieldMethod}(${finalKey}, ${field}, ${value})`);
2708
2707
  await connection[setFieldMethod](finalKey, field, value);
2709
2708
  } catch (singleError) {
2710
- this.logger('error', `设置单个字段失败 ${field}: ${singleError.message}`);
2709
+ this.log('error', `设置单个字段失败 ${field}: ${singleError.message}`);
2711
2710
  success = false;
2712
2711
  break;
2713
2712
  }
@@ -2716,19 +2715,19 @@ Redis.prototype.hmset = async function (key, obj) {
2716
2715
 
2717
2716
  // 验证所有字段是否都设置成功
2718
2717
  if (success) {
2719
- this.logger('debug', `验证所有字段设置情况`);
2718
+ this.log('debug', `验证所有字段设置情况`);
2720
2719
  for (const field in finalObj) {
2721
2720
  if (finalObj.hasOwnProperty(field)) {
2722
2721
  try {
2723
2722
  const hgetMethod = typeof connection.hGet === 'function' ? 'hGet' : 'hget';
2724
2723
  const value = await connection[hgetMethod](finalKey, field);
2725
- this.logger('debug', `验证字段 ${field}: ${value !== null ? '存在' : '不存在'}`);
2724
+ this.log('debug', `验证字段 ${field}: ${value !== null ? '存在' : '不存在'}`);
2726
2725
  // 如果字段不存在,更新success状态
2727
2726
  if (value === null) {
2728
2727
  success = false;
2729
2728
  }
2730
2729
  } catch (getError) {
2731
- this.logger('error', `验证字段失败 ${field}: ${getError.message}`);
2730
+ this.log('error', `验证字段失败 ${field}: ${getError.message}`);
2732
2731
  success = false;
2733
2732
  }
2734
2733
  }
@@ -2746,7 +2745,7 @@ Redis.prototype.hmset = async function (key, obj) {
2746
2745
  this._recycleConnection(connection);
2747
2746
  }
2748
2747
  } catch (err) {
2749
- this.logger('error', `批量设置哈希字段失败 [${key}]:`, err);
2748
+ this.log('error', `批量设置哈希字段失败 [${key}]:`, err);
2750
2749
  // 触发错误事件
2751
2750
  this.emit('hmset:error', {
2752
2751
  key,
@@ -2771,14 +2770,14 @@ Redis.prototype.hgetall = async function (key) {
2771
2770
  const result = await connection.hGetAll(key);
2772
2771
  return result;
2773
2772
  } else {
2774
- this.logger('error', '连接对象不支持hGetAll操作');
2773
+ this.log('error', '连接对象不支持hGetAll操作');
2775
2774
  return {};
2776
2775
  }
2777
2776
  } finally {
2778
2777
  this._recycleConnection(connection);
2779
2778
  }
2780
2779
  } catch (err) {
2781
- this.logger('error', `获取哈希所有字段和值失败 [${key}]:`, err);
2780
+ this.log('error', `获取哈希所有字段和值失败 [${key}]:`, err);
2782
2781
  return {};
2783
2782
  }
2784
2783
  };
@@ -2828,8 +2827,8 @@ Redis.prototype.hmget = async function (key, fields) {
2828
2827
  });
2829
2828
  return finalResult;
2830
2829
  } else {
2831
- this.logger('error', '连接对象不支持hmGet操作');
2832
- this.logger('error', '错误: Redis客户端不支持hmget操作');
2830
+ this.log('error', '连接对象不支持hmGet操作');
2831
+ this.log('error', '错误: Redis客户端不支持hmget操作');
2833
2832
  // 返回与fields长度相同的undefined数组,保持与注释一致
2834
2833
  return fields.map(() => undefined);
2835
2834
  }
@@ -2842,7 +2841,7 @@ Redis.prototype.hmget = async function (key, fields) {
2842
2841
  fields,
2843
2842
  error: err
2844
2843
  });
2845
- this.logger('error', `哈希表批量获取失败 [${key}]:`, err);
2844
+ this.log('error', `哈希表批量获取失败 [${key}]:`, err);
2846
2845
  // 返回与fields长度相同的undefined数组,保持与注释类型一致
2847
2846
  return fields.map(() => undefined);
2848
2847
  }
@@ -2864,7 +2863,7 @@ Redis.prototype.expire = async function (key, seconds) {
2864
2863
  this.emit('expire:before', ctx);
2865
2864
 
2866
2865
  if (ctx.cancel) {
2867
- this.logger('debug', `expire操作被事件处理器取消 [${key}]`);
2866
+ this.log('debug', `expire操作被事件处理器取消 [${key}]`);
2868
2867
  return false;
2869
2868
  }
2870
2869
 
@@ -2886,7 +2885,7 @@ Redis.prototype.expire = async function (key, seconds) {
2886
2885
  });
2887
2886
  return result === 1;
2888
2887
  } catch (err) {
2889
- this.logger('error', `设置过期时间失败 [${finalKey}]:`, err);
2888
+ this.log('error', `设置过期时间失败 [${finalKey}]:`, err);
2890
2889
  this.emit('expire:error', {
2891
2890
  key: finalKey,
2892
2891
  ttl: finalSeconds,
@@ -2897,7 +2896,7 @@ Redis.prototype.expire = async function (key, seconds) {
2897
2896
  this._recycleConnection(connection);
2898
2897
  }
2899
2898
  } catch (err) {
2900
- this.logger('error', `设置过期时间失败 [${key}]:`, err);
2899
+ this.log('error', `设置过期时间失败 [${key}]:`, err);
2901
2900
  this.emit('expire:error', {
2902
2901
  key,
2903
2902
  ttl: seconds,
@@ -2932,7 +2931,7 @@ Redis.prototype.pexpire = async function (key, milliseconds) {
2932
2931
  this.emit('pexpire:before', ctx);
2933
2932
 
2934
2933
  if (ctx.cancel) {
2935
- this.logger('debug', `pexpire操作被事件处理器取消 [${key}]`);
2934
+ this.log('debug', `pexpire操作被事件处理器取消 [${key}]`);
2936
2935
  return false;
2937
2936
  }
2938
2937
 
@@ -2950,7 +2949,7 @@ Redis.prototype.pexpire = async function (key, milliseconds) {
2950
2949
  } else if (typeof connection.execute === 'function') {
2951
2950
  result = await connection.execute('PEXPIRE', [this._addPrefix(finalKey), finalMilliseconds]);
2952
2951
  } else {
2953
- this.logger('error', '连接对象不支持pexpire操作');
2952
+ this.log('error', '连接对象不支持pexpire操作');
2954
2953
  return false;
2955
2954
  }
2956
2955
 
@@ -2962,7 +2961,7 @@ Redis.prototype.pexpire = async function (key, milliseconds) {
2962
2961
  });
2963
2962
  return result === 1;
2964
2963
  } catch (err) {
2965
- this.logger('error', `设置过期时间(毫秒)失败 [${finalKey}]:`, err);
2964
+ this.log('error', `设置过期时间(毫秒)失败 [${finalKey}]:`, err);
2966
2965
  this.emit('pexpire:error', {
2967
2966
  key: finalKey,
2968
2967
  ttl: finalMilliseconds,
@@ -2973,7 +2972,7 @@ Redis.prototype.pexpire = async function (key, milliseconds) {
2973
2972
  this._recycleConnection(connection);
2974
2973
  }
2975
2974
  } catch (err) {
2976
- this.logger('error', `设置过期时间(毫秒)失败 [${key}]:`, err);
2975
+ this.log('error', `设置过期时间(毫秒)失败 [${key}]:`, err);
2977
2976
  this.emit('pexpire:error', {
2978
2977
  key,
2979
2978
  ttl: milliseconds,
@@ -2994,7 +2993,7 @@ Redis.prototype.persist = async function (key) {
2994
2993
  this.emit('persist:before', ctx);
2995
2994
 
2996
2995
  if (ctx.cancel) {
2997
- this.logger('debug', `persist操作被事件处理器取消 [${key}]`);
2996
+ this.log('debug', `persist操作被事件处理器取消 [${key}]`);
2998
2997
  return false;
2999
2998
  }
3000
2999
 
@@ -3014,7 +3013,7 @@ Redis.prototype.persist = async function (key) {
3014
3013
  });
3015
3014
  return result === 1;
3016
3015
  } catch (err) {
3017
- this.logger('error', `移除过期时间失败 [${finalKey}]:`, err);
3016
+ this.log('error', `移除过期时间失败 [${finalKey}]:`, err);
3018
3017
  this.emit('persist:error', {
3019
3018
  key: finalKey,
3020
3019
  error: err
@@ -3024,7 +3023,7 @@ Redis.prototype.persist = async function (key) {
3024
3023
  this._recycleConnection(connection);
3025
3024
  }
3026
3025
  } catch (err) {
3027
- this.logger('error', `移除过期时间失败 [${key}]:`, err);
3026
+ this.log('error', `移除过期时间失败 [${key}]:`, err);
3028
3027
  this.emit('persist:error', {
3029
3028
  key,
3030
3029
  error: err
@@ -3055,7 +3054,7 @@ Redis.prototype.incr = async function (key, seconds = 0) {
3055
3054
  this.emit('incr:before', ctx);
3056
3055
 
3057
3056
  if (ctx.cancel) {
3058
- this.logger('debug', `incr操作被事件处理器取消 [${key}]`);
3057
+ this.log('debug', `incr操作被事件处理器取消 [${key}]`);
3059
3058
  return null;
3060
3059
  }
3061
3060
 
@@ -3086,7 +3085,7 @@ Redis.prototype.incr = async function (key, seconds = 0) {
3086
3085
  });
3087
3086
  return result;
3088
3087
  } catch (err) {
3089
- this.logger('error', `增加整数值失败 [${finalKey}]:`, err);
3088
+ this.log('error', `增加整数值失败 [${finalKey}]:`, err);
3090
3089
  this.emit('incr:error', {
3091
3090
  key: finalKey,
3092
3091
  seconds: finalSeconds,
@@ -3097,7 +3096,7 @@ Redis.prototype.incr = async function (key, seconds = 0) {
3097
3096
  this._recycleConnection(connection);
3098
3097
  }
3099
3098
  } catch (err) {
3100
- this.logger('error', `增加整数值失败 [${key}]:`, err);
3099
+ this.log('error', `增加整数值失败 [${key}]:`, err);
3101
3100
  this.emit('incr:error', {
3102
3101
  key,
3103
3102
  seconds,
@@ -3129,7 +3128,7 @@ Redis.prototype.decr = async function (key, seconds = 0) {
3129
3128
  this.emit('decr:before', ctx);
3130
3129
 
3131
3130
  if (ctx.cancel) {
3132
- this.logger('debug', `decr操作被事件处理器取消 [${key}]`);
3131
+ this.log('debug', `decr操作被事件处理器取消 [${key}]`);
3133
3132
  return null;
3134
3133
  }
3135
3134
 
@@ -3160,7 +3159,7 @@ Redis.prototype.decr = async function (key, seconds = 0) {
3160
3159
  });
3161
3160
  return result;
3162
3161
  } catch (err) {
3163
- this.logger('error', `减少整数值失败 [${finalKey}]:`, err);
3162
+ this.log('error', `减少整数值失败 [${finalKey}]:`, err);
3164
3163
  this.emit('decr:error', {
3165
3164
  key: finalKey,
3166
3165
  seconds: finalSeconds,
@@ -3171,7 +3170,7 @@ Redis.prototype.decr = async function (key, seconds = 0) {
3171
3170
  this._recycleConnection(connection);
3172
3171
  }
3173
3172
  } catch (err) {
3174
- this.logger('error', `减少整数值失败 [${key}]:`, err);
3173
+ this.log('error', `减少整数值失败 [${key}]:`, err);
3175
3174
  this.emit('decr:error', {
3176
3175
  key,
3177
3176
  seconds,
@@ -3208,7 +3207,7 @@ Redis.prototype.incrbyfloat = async function (key, increment, seconds = 0) {
3208
3207
  this.emit('incrbyfloat:before', ctx);
3209
3208
 
3210
3209
  if (ctx.cancel) {
3211
- this.logger('debug', `incrbyfloat操作被事件处理器取消 [${key}]`);
3210
+ this.log('debug', `incrbyfloat操作被事件处理器取消 [${key}]`);
3212
3211
  return null;
3213
3212
  }
3214
3213
 
@@ -3242,7 +3241,7 @@ Redis.prototype.incrbyfloat = async function (key, increment, seconds = 0) {
3242
3241
  });
3243
3242
  return parsedResult;
3244
3243
  } catch (err) {
3245
- this.logger('error', `增加浮点数值失败 [${finalKey}]:`, err);
3244
+ this.log('error', `增加浮点数值失败 [${finalKey}]:`, err);
3246
3245
  this.emit('incrbyfloat:error', {
3247
3246
  key: finalKey,
3248
3247
  increment: finalIncrement,
@@ -3254,7 +3253,7 @@ Redis.prototype.incrbyfloat = async function (key, increment, seconds = 0) {
3254
3253
  this._recycleConnection(connection);
3255
3254
  }
3256
3255
  } catch (err) {
3257
- this.logger('error', `增加浮点数值失败 [${key}]:`, err);
3256
+ this.log('error', `增加浮点数值失败 [${key}]:`, err);
3258
3257
  this.emit('incrbyfloat:error', {
3259
3258
  key,
3260
3259
  increment,
@@ -3292,7 +3291,7 @@ Redis.prototype.incrby = async function (key, increment, seconds = 0) {
3292
3291
  this.emit('incrby:before', ctx);
3293
3292
 
3294
3293
  if (ctx.cancel) {
3295
- this.logger('debug', `incrby操作被事件处理器取消 [${key}]`);
3294
+ this.log('debug', `incrby操作被事件处理器取消 [${key}]`);
3296
3295
  return null;
3297
3296
  }
3298
3297
 
@@ -3325,7 +3324,7 @@ Redis.prototype.incrby = async function (key, increment, seconds = 0) {
3325
3324
  });
3326
3325
  return result;
3327
3326
  } catch (err) {
3328
- this.logger('error', `增加指定值失败 [${finalKey}]:`, err);
3327
+ this.log('error', `增加指定值失败 [${finalKey}]:`, err);
3329
3328
  this.emit('incrby:error', {
3330
3329
  key: finalKey,
3331
3330
  increment: finalIncrement,
@@ -3337,7 +3336,7 @@ Redis.prototype.incrby = async function (key, increment, seconds = 0) {
3337
3336
  this._recycleConnection(connection);
3338
3337
  }
3339
3338
  } catch (err) {
3340
- this.logger('error', `增加指定值失败 [${key}]:`, err);
3339
+ this.log('error', `增加指定值失败 [${key}]:`, err);
3341
3340
  this.emit('incrby:error', {
3342
3341
  key,
3343
3342
  increment,
@@ -3375,7 +3374,7 @@ Redis.prototype.decrby = async function (key, decrement, seconds = 0) {
3375
3374
  this.emit('decrby:before', ctx);
3376
3375
 
3377
3376
  if (ctx.cancel) {
3378
- this.logger('debug', `decrby操作被事件处理器取消 [${key}]`);
3377
+ this.log('debug', `decrby操作被事件处理器取消 [${key}]`);
3379
3378
  return null;
3380
3379
  }
3381
3380
 
@@ -3408,7 +3407,7 @@ Redis.prototype.decrby = async function (key, decrement, seconds = 0) {
3408
3407
  });
3409
3408
  return result;
3410
3409
  } catch (err) {
3411
- this.logger('error', `减少指定值失败 [${finalKey}]:`, err);
3410
+ this.log('error', `减少指定值失败 [${finalKey}]:`, err);
3412
3411
  this.emit('decrby:error', {
3413
3412
  key: finalKey,
3414
3413
  decrement: finalDecrement,
@@ -3420,7 +3419,7 @@ Redis.prototype.decrby = async function (key, decrement, seconds = 0) {
3420
3419
  this._recycleConnection(connection);
3421
3420
  }
3422
3421
  } catch (err) {
3423
- this.logger('error', `减少指定值失败 [${key}]:`, err);
3422
+ this.log('error', `减少指定值失败 [${key}]:`, err);
3424
3423
  this.emit('decrby:error', {
3425
3424
  key,
3426
3425
  decrement,
@@ -3450,7 +3449,7 @@ Redis.prototype.sadd = async function (key, members) {
3450
3449
  this.emit('sadd:before', ctx);
3451
3450
 
3452
3451
  if (ctx.cancel) {
3453
- this.logger('debug', `sadd操作被事件处理器取消 [${key}]`);
3452
+ this.log('debug', `sadd操作被事件处理器取消 [${key}]`);
3454
3453
  return 0;
3455
3454
  }
3456
3455
 
@@ -3475,7 +3474,7 @@ Redis.prototype.sadd = async function (key, members) {
3475
3474
  this._recycleConnection(connection);
3476
3475
  }
3477
3476
  } catch (err) {
3478
- this.logger('error', `添加集合成员失败 [${key}]:`, err);
3477
+ this.log('error', `添加集合成员失败 [${key}]:`, err);
3479
3478
  this.emit('sadd:error', {
3480
3479
  key,
3481
3480
  members,
@@ -3502,7 +3501,7 @@ Redis.prototype.srem = async function (key, members) {
3502
3501
  this.emit('srem:before', ctx);
3503
3502
 
3504
3503
  if (ctx.cancel) {
3505
- this.logger('debug', `srem操作被事件处理器取消 [${key}]`);
3504
+ this.log('debug', `srem操作被事件处理器取消 [${key}]`);
3506
3505
  return 0;
3507
3506
  }
3508
3507
 
@@ -3527,7 +3526,7 @@ Redis.prototype.srem = async function (key, members) {
3527
3526
  this._recycleConnection(connection);
3528
3527
  }
3529
3528
  } catch (err) {
3530
- this.logger('error', `移除集合成员失败 [${key}]:`, err);
3529
+ this.log('error', `移除集合成员失败 [${key}]:`, err);
3531
3530
  this.emit('srem:error', {
3532
3531
  key,
3533
3532
  members,
@@ -3578,7 +3577,7 @@ Redis.prototype.sismember = async function (key, member) {
3578
3577
  member,
3579
3578
  error: err
3580
3579
  });
3581
- this.logger('error', `检查集合成员失败 [${key}:${member}]:`, err);
3580
+ this.log('error', `检查集合成员失败 [${key}:${member}]:`, err);
3582
3581
  return false;
3583
3582
  }
3584
3583
  };
@@ -3603,7 +3602,7 @@ Redis.prototype.smembers = async function (key) {
3603
3602
  this._recycleConnection(connection);
3604
3603
  }
3605
3604
  } catch (err) {
3606
- this.logger('error', `获取集合所有成员失败 [${key}]:`, err);
3605
+ this.log('error', `获取集合所有成员失败 [${key}]:`, err);
3607
3606
  this.emit('smembers:error', {
3608
3607
  key,
3609
3608
  error: err
@@ -3628,7 +3627,7 @@ Redis.prototype.scard = async function (key) {
3628
3627
  this._recycleConnection(connection);
3629
3628
  }
3630
3629
  } catch (err) {
3631
- this.logger('error', `获取集合大小失败 [${key}]:`, err);
3630
+ this.log('error', `获取集合大小失败 [${key}]:`, err);
3632
3631
  return 0;
3633
3632
  }
3634
3633
  };
@@ -3650,7 +3649,7 @@ Redis.prototype.sinter = async function (keys) {
3650
3649
  this._recycleConnection(connection);
3651
3650
  }
3652
3651
  } catch (err) {
3653
- this.logger('error', `获取集合交集失败:`, err);
3652
+ this.log('error', `获取集合交集失败:`, err);
3654
3653
  return [];
3655
3654
  }
3656
3655
  };
@@ -3672,7 +3671,7 @@ Redis.prototype.sunion = async function (keys) {
3672
3671
  this._recycleConnection(connection);
3673
3672
  }
3674
3673
  } catch (err) {
3675
- this.logger('error', `获取集合并集失败:`, err);
3674
+ this.log('error', `获取集合并集失败:`, err);
3676
3675
  return [];
3677
3676
  }
3678
3677
  };
@@ -3694,7 +3693,7 @@ Redis.prototype.sdiff = async function (keys) {
3694
3693
  this._recycleConnection(connection);
3695
3694
  }
3696
3695
  } catch (err) {
3697
- this.logger('error', `获取集合差集失败:`, err);
3696
+ this.log('error', `获取集合差集失败:`, err);
3698
3697
  return [];
3699
3698
  }
3700
3699
  };
@@ -3720,7 +3719,7 @@ Redis.prototype.zadd = async function (key, score, member) {
3720
3719
  this.emit('zadd:before', ctx);
3721
3720
 
3722
3721
  if (ctx.cancel) {
3723
- this.logger('debug', `zadd操作被事件处理器取消 [${key}]`);
3722
+ this.log('debug', `zadd操作被事件处理器取消 [${key}]`);
3724
3723
  return false;
3725
3724
  }
3726
3725
 
@@ -3750,7 +3749,7 @@ Redis.prototype.zadd = async function (key, score, member) {
3750
3749
  this._recycleConnection(connection);
3751
3750
  }
3752
3751
  } catch (err) {
3753
- this.logger('error', `添加有序集合成员失败 [${key}]:`, err);
3752
+ this.log('error', `添加有序集合成员失败 [${key}]:`, err);
3754
3753
  this.emit('zadd:error', {
3755
3754
  key,
3756
3755
  score,
@@ -3778,7 +3777,7 @@ Redis.prototype.zrem = async function (key, members) {
3778
3777
  this.emit('zrem:before', ctx);
3779
3778
 
3780
3779
  if (ctx.cancel) {
3781
- this.logger('debug', `zrem操作被事件处理器取消 [${key}]`);
3780
+ this.log('debug', `zrem操作被事件处理器取消 [${key}]`);
3782
3781
  return 0;
3783
3782
  }
3784
3783
 
@@ -3800,7 +3799,7 @@ Redis.prototype.zrem = async function (key, members) {
3800
3799
  });
3801
3800
  return result;
3802
3801
  } catch (err) {
3803
- this.logger('error', `移除有序集合成员失败 [${finalKey}]:`, err);
3802
+ this.log('error', `移除有序集合成员失败 [${finalKey}]:`, err);
3804
3803
  this.emit('zrem:error', {
3805
3804
  key: finalKey,
3806
3805
  members: finalMembers,
@@ -3811,7 +3810,7 @@ Redis.prototype.zrem = async function (key, members) {
3811
3810
  this._recycleConnection(connection);
3812
3811
  }
3813
3812
  } catch (err) {
3814
- this.logger('error', `移除有序集合成员失败 [${key}]:`, err);
3813
+ this.log('error', `移除有序集合成员失败 [${key}]:`, err);
3815
3814
  this.emit('zrem:error', {
3816
3815
  key,
3817
3816
  members,
@@ -3838,7 +3837,7 @@ Redis.prototype.zscore = async function (key, member) {
3838
3837
  this._recycleConnection(connection);
3839
3838
  }
3840
3839
  } catch (err) {
3841
- this.logger('error', `获取有序集合成员分数失败 [${key}:${member}]:`, err);
3840
+ this.log('error', `获取有序集合成员分数失败 [${key}:${member}]:`, err);
3842
3841
  return null;
3843
3842
  }
3844
3843
  };
@@ -3860,7 +3859,7 @@ Redis.prototype.zrank = async function (key, member) {
3860
3859
  this._recycleConnection(connection);
3861
3860
  }
3862
3861
  } catch (err) {
3863
- this.logger('error', `获取有序集合成员排名失败 [${key}:${member}]:`, err);
3862
+ this.log('error', `获取有序集合成员排名失败 [${key}:${member}]:`, err);
3864
3863
  return null;
3865
3864
  }
3866
3865
  };
@@ -3901,13 +3900,13 @@ Redis.prototype.zrange = async function (key, start, stop, withScores = false) {
3901
3900
  member,
3902
3901
  score: 0
3903
3902
  });
3904
- this.logger('error', `获取成员 ${member} 分数失败:`, scoreErr);
3903
+ this.log('error', `获取成员 ${member} 分数失败:`, scoreErr);
3905
3904
  }
3906
3905
  }
3907
3906
 
3908
3907
  return results;
3909
3908
  } catch (err) {
3910
- this.logger('error', `使用备用方法获取有序集合范围失败 [${prefixedKey}]:`, err);
3909
+ this.log('error', `使用备用方法获取有序集合范围失败 [${prefixedKey}]:`, err);
3911
3910
  // 回退到简单列表
3912
3911
  return [];
3913
3912
  }
@@ -3920,7 +3919,7 @@ Redis.prototype.zrange = async function (key, start, stop, withScores = false) {
3920
3919
  this._recycleConnection(connection);
3921
3920
  }
3922
3921
  } catch (err) {
3923
- this.logger('error', `获取有序集合范围成员失败 [${key}]:`, err);
3922
+ this.log('error', `获取有序集合范围成员失败 [${key}]:`, err);
3924
3923
  return [];
3925
3924
  }
3926
3925
  };
@@ -3938,13 +3937,13 @@ Redis.prototype.zcard = async function (key) {
3938
3937
  const result = await connection.zCard(this._addPrefix(key));
3939
3938
  return result || 0;
3940
3939
  } catch (err) {
3941
- this.logger('error', `获取有序集合成员数量失败 [${key}]:`, err);
3940
+ this.log('error', `获取有序集合成员数量失败 [${key}]:`, err);
3942
3941
  return 0;
3943
3942
  } finally {
3944
3943
  this._recycleConnection(connection);
3945
3944
  }
3946
3945
  } catch (err) {
3947
- this.logger('error', `获取有序集合成员数量失败 [${key}]:`, err);
3946
+ this.log('error', `获取有序集合成员数量失败 [${key}]:`, err);
3948
3947
  return 0;
3949
3948
  }
3950
3949
  };
@@ -3981,7 +3980,7 @@ Redis.prototype.zincrby = async function (key, increment, member, seconds = 0) {
3981
3980
  this.emit('zincrby:before', ctx);
3982
3981
 
3983
3982
  if (ctx.cancel) {
3984
- this.logger('debug', `zincrby操作被事件处理器取消 [${key}]`);
3983
+ this.log('debug', `zincrby操作被事件处理器取消 [${key}]`);
3985
3984
  return null;
3986
3985
  }
3987
3986
 
@@ -4017,7 +4016,7 @@ Redis.prototype.zincrby = async function (key, increment, member, seconds = 0) {
4017
4016
  });
4018
4017
  return parseFloat(result);
4019
4018
  } catch (err) {
4020
- this.logger('error', `增加有序集合成员分数失败 [${finalKey}]:`, err);
4019
+ this.log('error', `增加有序集合成员分数失败 [${finalKey}]:`, err);
4021
4020
  this.emit('zincrby:error', {
4022
4021
  key: finalKey,
4023
4022
  increment: finalIncrement,
@@ -4030,7 +4029,7 @@ Redis.prototype.zincrby = async function (key, increment, member, seconds = 0) {
4030
4029
  this._recycleConnection(connection);
4031
4030
  }
4032
4031
  } catch (err) {
4033
- this.logger('error', `增加有序集合成员分数失败 [${key}]:`, err);
4032
+ this.log('error', `增加有序集合成员分数失败 [${key}]:`, err);
4034
4033
  this.emit('zincrby:error', {
4035
4034
  key,
4036
4035
  increment,
@@ -4064,26 +4063,24 @@ Redis.prototype._createConnection = function () {
4064
4063
 
4065
4064
  // 监听错误事件
4066
4065
  connection.on('error', (err) => {
4067
- this.logger('error', `连接 ${connection.id} 错误:`, err);
4066
+ this.log('error', `连接 ${connection.id} 错误:`, err);
4068
4067
  });
4069
4068
 
4070
4069
  // 连接Redis
4071
4070
  connection.connect().then(() => {
4072
- // this.logger('debug','新连接已创建并连接:', connection.id);
4071
+ // this.log('debug','新连接已创建并连接:', connection.id);
4073
4072
  resolve(connection);
4074
4073
  }).catch(err => {
4075
- this.logger('error', '创建连接失败:', err);
4074
+ this.log('error', '创建连接失败:', err);
4076
4075
  reject(err);
4077
4076
  });
4078
4077
  } catch (error) {
4079
- this.logger('error', '创建连接时发生异常:', error);
4078
+ this.log('error', '创建连接时发生异常:', error);
4080
4079
  reject(error);
4081
4080
  }
4082
4081
  });
4083
4082
  };
4084
4083
 
4085
- // 修改导出方式以支持多种导入格式
4086
- exports.Redis = Redis;
4087
4084
 
4088
4085
  /**
4089
4086
  * 确保连接池对象存在
@@ -4113,7 +4110,7 @@ function redisAdmin(scope, config) {
4113
4110
  return obj;
4114
4111
  }
4115
4112
 
4116
- /**
4117
- * @module 导出Redis管理器
4118
- */
4119
- exports.redisAdmin = redisAdmin;
4113
+ module.exports = {
4114
+ Redis,
4115
+ redisAdmin
4116
+ };