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