1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.enable = exports.redis = void 0;
|
4 |
|
5 |
|
6 | var diagnostic_channel_1 = require("diagnostic-channel");
|
7 | var redisPatchFunction = function (originalRedis) {
|
8 | var originalSend = originalRedis.RedisClient.prototype.internal_send_command;
|
9 |
|
10 | originalRedis.RedisClient.prototype.internal_send_command = function (commandObj) {
|
11 | if (commandObj) {
|
12 | var cb_1 = commandObj.callback;
|
13 | if (!cb_1 || !cb_1.pubsubBound) {
|
14 | var address_1 = this.address;
|
15 | var startTime_1 = process.hrtime();
|
16 | var startDate_1 = new Date();
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | commandObj.callback = diagnostic_channel_1.channel.bindToContext(function (err, result) {
|
22 | var hrDuration = process.hrtime(startTime_1);
|
23 |
|
24 | var duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
|
25 | diagnostic_channel_1.channel.publish("redis", { duration: duration, address: address_1, commandObj: commandObj, err: err, result: result, time: startDate_1 });
|
26 | if (typeof cb_1 === "function") {
|
27 | cb_1.apply(this, arguments);
|
28 | }
|
29 | });
|
30 | commandObj.callback.pubsubBound = true;
|
31 | }
|
32 | }
|
33 | return originalSend.call(this, commandObj);
|
34 | };
|
35 | return originalRedis;
|
36 | };
|
37 | exports.redis = {
|
38 | versionSpecifier: ">= 2.0.0 < 4.0.0",
|
39 | patch: redisPatchFunction,
|
40 | };
|
41 | function enable() {
|
42 | diagnostic_channel_1.channel.registerMonkeyPatch("redis", exports.redis);
|
43 | }
|
44 | exports.enable = enable;
|
45 |
|
\ | No newline at end of file |