ioredis-om 5.10.2
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.
Potentially problematic release.
This version of ioredis-om might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +1571 -0
- package/built/Command.d.ts +166 -0
- package/built/Command.js +450 -0
- package/built/DataHandler.d.ts +37 -0
- package/built/DataHandler.js +224 -0
- package/built/Pipeline.d.ts +31 -0
- package/built/Pipeline.js +342 -0
- package/built/Redis.d.ts +243 -0
- package/built/Redis.js +800 -0
- package/built/ScanStream.d.ts +23 -0
- package/built/ScanStream.js +51 -0
- package/built/Script.d.ts +11 -0
- package/built/Script.js +62 -0
- package/built/SubscriptionSet.d.ts +14 -0
- package/built/SubscriptionSet.js +41 -0
- package/built/autoPipelining.d.ts +8 -0
- package/built/autoPipelining.js +167 -0
- package/built/cluster/ClusterOptions.d.ts +172 -0
- package/built/cluster/ClusterOptions.js +22 -0
- package/built/cluster/ClusterSubscriber.d.ts +29 -0
- package/built/cluster/ClusterSubscriber.js +223 -0
- package/built/cluster/ClusterSubscriberGroup.d.ts +108 -0
- package/built/cluster/ClusterSubscriberGroup.js +373 -0
- package/built/cluster/ConnectionPool.d.ts +37 -0
- package/built/cluster/ConnectionPool.js +154 -0
- package/built/cluster/DelayQueue.d.ts +20 -0
- package/built/cluster/DelayQueue.js +53 -0
- package/built/cluster/ShardedSubscriber.d.ts +36 -0
- package/built/cluster/ShardedSubscriber.js +147 -0
- package/built/cluster/index.d.ts +163 -0
- package/built/cluster/index.js +937 -0
- package/built/cluster/util.d.ts +25 -0
- package/built/cluster/util.js +100 -0
- package/built/connectors/AbstractConnector.d.ts +12 -0
- package/built/connectors/AbstractConnector.js +26 -0
- package/built/connectors/ConnectorConstructor.d.ts +5 -0
- package/built/connectors/ConnectorConstructor.js +2 -0
- package/built/connectors/SentinelConnector/FailoverDetector.d.ts +11 -0
- package/built/connectors/SentinelConnector/FailoverDetector.js +45 -0
- package/built/connectors/SentinelConnector/SentinelIterator.d.ts +13 -0
- package/built/connectors/SentinelConnector/SentinelIterator.js +37 -0
- package/built/connectors/SentinelConnector/index.d.ts +72 -0
- package/built/connectors/SentinelConnector/index.js +305 -0
- package/built/connectors/SentinelConnector/types.d.ts +21 -0
- package/built/connectors/SentinelConnector/types.js +2 -0
- package/built/connectors/StandaloneConnector.d.ts +17 -0
- package/built/connectors/StandaloneConnector.js +69 -0
- package/built/connectors/index.d.ts +3 -0
- package/built/connectors/index.js +7 -0
- package/built/constants/TLSProfiles.d.ts +9 -0
- package/built/constants/TLSProfiles.js +149 -0
- package/built/errors/ClusterAllFailedError.d.ts +7 -0
- package/built/errors/ClusterAllFailedError.js +15 -0
- package/built/errors/MaxRetriesPerRequestError.d.ts +5 -0
- package/built/errors/MaxRetriesPerRequestError.js +14 -0
- package/built/errors/index.d.ts +2 -0
- package/built/errors/index.js +5 -0
- package/built/index.d.ts +44 -0
- package/built/index.js +62 -0
- package/built/redis/RedisOptions.d.ts +197 -0
- package/built/redis/RedisOptions.js +58 -0
- package/built/redis/event_handler.d.ts +4 -0
- package/built/redis/event_handler.js +315 -0
- package/built/tracing.d.ts +26 -0
- package/built/tracing.js +96 -0
- package/built/transaction.d.ts +13 -0
- package/built/transaction.js +100 -0
- package/built/types.d.ts +33 -0
- package/built/types.js +2 -0
- package/built/utils/Commander.d.ts +50 -0
- package/built/utils/Commander.js +117 -0
- package/built/utils/RedisCommander.d.ts +8950 -0
- package/built/utils/RedisCommander.js +7 -0
- package/built/utils/applyMixin.d.ts +3 -0
- package/built/utils/applyMixin.js +8 -0
- package/built/utils/argumentParsers.d.ts +14 -0
- package/built/utils/argumentParsers.js +74 -0
- package/built/utils/debug.d.ts +16 -0
- package/built/utils/debug.js +95 -0
- package/built/utils/index.d.ts +124 -0
- package/built/utils/index.js +332 -0
- package/built/utils/lodash.d.ts +4 -0
- package/built/utils/lodash.js +9 -0
- package/package.json +103 -0
package/built/tracing.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traceConnect = exports.traceBatch = exports.traceCommand = exports.sanitizeArgs = void 0;
|
|
4
|
+
// Argument sanitization rules adapted from @opentelemetry/redis-common (Apache 2.0).
|
|
5
|
+
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/redis-common/src/index.ts
|
|
6
|
+
//
|
|
7
|
+
// Each entry specifies how many positional args (after the command name) are safe
|
|
8
|
+
// to emit. -1 means all args are safe (read-only/structural commands).
|
|
9
|
+
// Unlisted commands default to 0 (all args redacted) for safe-by-default behavior,
|
|
10
|
+
// which covers AUTH, HELLO, and unknown/custom commands.
|
|
11
|
+
const SERIALIZATION_SUBSETS = [
|
|
12
|
+
{ regex: /^ECHO/i, args: 0 },
|
|
13
|
+
{
|
|
14
|
+
regex: /^(LPUSH|MSET|PFA|PUBLISH|RPUSH|SADD|SET|SPUBLISH|XADD|ZADD)/i,
|
|
15
|
+
args: 1,
|
|
16
|
+
},
|
|
17
|
+
{ regex: /^(HSET|HMSET|LSET|LINSERT)/i, args: 2 },
|
|
18
|
+
{
|
|
19
|
+
regex: /^(ACL|BIT|B[LRZ]|CLIENT|CLUSTER|CONFIG|COMMAND|DECR|DEL|EVAL|EX|FUNCTION|GEO|GET|HINCR|HMGET|HSCAN|INCR|L[TRLM]|MEMORY|P[EFISTU]|RPOP|S[CDIMORSU]|XACK|X[CDGILPRT]|Z[CDILMPRS])/i,
|
|
20
|
+
args: -1,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
function sanitizeArgs(commandName, args) {
|
|
24
|
+
let allowedArgCount = 0;
|
|
25
|
+
for (const subset of SERIALIZATION_SUBSETS) {
|
|
26
|
+
if (subset.regex.test(commandName)) {
|
|
27
|
+
allowedArgCount = subset.args;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (allowedArgCount === -1) {
|
|
32
|
+
return args.map((a) => String(a));
|
|
33
|
+
}
|
|
34
|
+
const result = [];
|
|
35
|
+
for (let i = 0; i < args.length; i++) {
|
|
36
|
+
if (i < allowedArgCount) {
|
|
37
|
+
result.push(String(args[i]));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
result.push("?");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
exports.sanitizeArgs = sanitizeArgs;
|
|
46
|
+
// Load diagnostics_channel with Node 18 compatibility
|
|
47
|
+
const dc = (() => {
|
|
48
|
+
try {
|
|
49
|
+
return "getBuiltinModule" in process
|
|
50
|
+
? process.getBuiltinModule("node:diagnostics_channel")
|
|
51
|
+
: require("node:diagnostics_channel");
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
const hasTracingChannel = dc && typeof dc.tracingChannel === "function";
|
|
58
|
+
const commandChannel = hasTracingChannel
|
|
59
|
+
? dc.tracingChannel("ioredis-om:command")
|
|
60
|
+
: undefined;
|
|
61
|
+
const batchChannel = hasTracingChannel
|
|
62
|
+
? dc.tracingChannel("ioredis-om:batch")
|
|
63
|
+
: undefined;
|
|
64
|
+
const connectChannel = hasTracingChannel
|
|
65
|
+
? dc.tracingChannel("ioredis-om:connect")
|
|
66
|
+
: undefined;
|
|
67
|
+
function shouldTrace(channel) {
|
|
68
|
+
return !!channel && channel.hasSubscribers !== false;
|
|
69
|
+
}
|
|
70
|
+
const noop = () => { };
|
|
71
|
+
function traceCommand(fn, contextFactory) {
|
|
72
|
+
if (!shouldTrace(commandChannel))
|
|
73
|
+
return fn();
|
|
74
|
+
// tracePromise returns a wrapper promise that re-rejects on error.
|
|
75
|
+
// Silence the wrapper to prevent unhandled rejections when callers
|
|
76
|
+
// (e.g. Pipeline) discard the return value. Callers that await this
|
|
77
|
+
// promise still see the rejection through their own .then() chain.
|
|
78
|
+
const traced = commandChannel.tracePromise(fn, contextFactory());
|
|
79
|
+
traced.catch(noop);
|
|
80
|
+
return traced;
|
|
81
|
+
}
|
|
82
|
+
exports.traceCommand = traceCommand;
|
|
83
|
+
function traceBatch(fn, contextFactory) {
|
|
84
|
+
if (!shouldTrace(batchChannel))
|
|
85
|
+
return fn();
|
|
86
|
+
const traced = batchChannel.tracePromise(fn, contextFactory());
|
|
87
|
+
traced.catch(noop);
|
|
88
|
+
return traced;
|
|
89
|
+
}
|
|
90
|
+
exports.traceBatch = traceBatch;
|
|
91
|
+
function traceConnect(fn, contextFactory) {
|
|
92
|
+
if (!shouldTrace(connectChannel))
|
|
93
|
+
return fn();
|
|
94
|
+
return connectChannel.tracePromise(fn, contextFactory());
|
|
95
|
+
}
|
|
96
|
+
exports.traceConnect = traceConnect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChainableCommander } from "./utils/RedisCommander";
|
|
2
|
+
export interface Transaction {
|
|
3
|
+
pipeline(commands?: unknown[][]): ChainableCommander;
|
|
4
|
+
multi(options: {
|
|
5
|
+
pipeline: false;
|
|
6
|
+
}): Promise<"OK">;
|
|
7
|
+
multi(): ChainableCommander;
|
|
8
|
+
multi(options: {
|
|
9
|
+
pipeline: true;
|
|
10
|
+
}): ChainableCommander;
|
|
11
|
+
multi(commands?: unknown[][]): ChainableCommander;
|
|
12
|
+
}
|
|
13
|
+
export declare function addTransactionSupport(redis: any): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addTransactionSupport = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const standard_as_callback_1 = require("standard-as-callback");
|
|
6
|
+
const Pipeline_1 = require("./Pipeline");
|
|
7
|
+
const tracing_1 = require("./tracing");
|
|
8
|
+
function addTransactionSupport(redis) {
|
|
9
|
+
redis.pipeline = function (commands) {
|
|
10
|
+
const pipeline = new Pipeline_1.default(this);
|
|
11
|
+
if (Array.isArray(commands)) {
|
|
12
|
+
pipeline.addBatch(commands);
|
|
13
|
+
}
|
|
14
|
+
return pipeline;
|
|
15
|
+
};
|
|
16
|
+
const { multi } = redis;
|
|
17
|
+
redis.multi = function (commands, options) {
|
|
18
|
+
if (typeof options === "undefined" && !Array.isArray(commands)) {
|
|
19
|
+
options = commands;
|
|
20
|
+
commands = null;
|
|
21
|
+
}
|
|
22
|
+
if (options && options.pipeline === false) {
|
|
23
|
+
return multi.call(this);
|
|
24
|
+
}
|
|
25
|
+
const pipeline = new Pipeline_1.default(this);
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
pipeline.multi();
|
|
28
|
+
if (Array.isArray(commands)) {
|
|
29
|
+
pipeline.addBatch(commands);
|
|
30
|
+
}
|
|
31
|
+
const exec = pipeline.exec;
|
|
32
|
+
pipeline.exec = function (callback) {
|
|
33
|
+
// Wait for the cluster to be connected, since we need nodes information before continuing
|
|
34
|
+
if (this.isCluster && !this.redis.slots.length) {
|
|
35
|
+
if (this.redis.status === "wait")
|
|
36
|
+
this.redis.connect().catch(utils_1.noop);
|
|
37
|
+
return (0, standard_as_callback_1.default)(new Promise((resolve, reject) => {
|
|
38
|
+
this.redis.delayUntilReady((err) => {
|
|
39
|
+
if (err) {
|
|
40
|
+
reject(err);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.exec(pipeline).then(resolve, reject);
|
|
44
|
+
});
|
|
45
|
+
}), callback);
|
|
46
|
+
}
|
|
47
|
+
if (this._transactions > 0) {
|
|
48
|
+
exec.call(pipeline);
|
|
49
|
+
}
|
|
50
|
+
// Returns directly when the pipeline
|
|
51
|
+
// has been called multiple times (retries).
|
|
52
|
+
if (this.nodeifiedPromise) {
|
|
53
|
+
return exec.call(pipeline);
|
|
54
|
+
}
|
|
55
|
+
// Count only user commands (exclude MULTI/EXEC wrappers).
|
|
56
|
+
const batchSize = Math.max(pipeline.length - 2, 0);
|
|
57
|
+
const execAndUnwrap = () => exec.call(pipeline).then(function (result) {
|
|
58
|
+
const execResult = result[result.length - 1];
|
|
59
|
+
if (typeof execResult === "undefined") {
|
|
60
|
+
throw new Error("Pipeline cannot be used to send any commands when the `exec()` has been called on it.");
|
|
61
|
+
}
|
|
62
|
+
if (execResult[0]) {
|
|
63
|
+
execResult[0].previousErrors = [];
|
|
64
|
+
for (let i = 0; i < result.length - 1; ++i) {
|
|
65
|
+
if (result[i][0]) {
|
|
66
|
+
execResult[0].previousErrors.push(result[i][0]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw execResult[0];
|
|
70
|
+
}
|
|
71
|
+
return (0, utils_1.wrapMultiResult)(execResult[1]);
|
|
72
|
+
});
|
|
73
|
+
// Trace MULTI as a single batch operation on ioredis-om:batch.
|
|
74
|
+
const promise = "_buildBatchContext" in this.redis
|
|
75
|
+
? (0, tracing_1.traceBatch)(execAndUnwrap, () => this.redis._buildBatchContext(batchSize))
|
|
76
|
+
: execAndUnwrap();
|
|
77
|
+
return (0, standard_as_callback_1.default)(promise, callback);
|
|
78
|
+
};
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
const { execBuffer } = pipeline;
|
|
81
|
+
// @ts-expect-error
|
|
82
|
+
pipeline.execBuffer = function (callback) {
|
|
83
|
+
if (this._transactions > 0) {
|
|
84
|
+
execBuffer.call(pipeline);
|
|
85
|
+
}
|
|
86
|
+
return pipeline.exec(callback);
|
|
87
|
+
};
|
|
88
|
+
return pipeline;
|
|
89
|
+
};
|
|
90
|
+
const { exec } = redis;
|
|
91
|
+
redis.exec = function (callback) {
|
|
92
|
+
return (0, standard_as_callback_1.default)(exec.call(this).then(function (results) {
|
|
93
|
+
if (Array.isArray(results)) {
|
|
94
|
+
results = (0, utils_1.wrapMultiResult)(results);
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
97
|
+
}), callback);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.addTransactionSupport = addTransactionSupport;
|
package/built/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Socket } from "net";
|
|
3
|
+
import { TLSSocket } from "tls";
|
|
4
|
+
export declare type Callback<T = any> = (err?: Error | null, result?: T) => void;
|
|
5
|
+
export declare type NetStream = Socket | TLSSocket;
|
|
6
|
+
export declare type CommandParameter = string | Buffer | number | any[];
|
|
7
|
+
export interface Respondable {
|
|
8
|
+
name: string;
|
|
9
|
+
args: CommandParameter[];
|
|
10
|
+
resolve(result: any): void;
|
|
11
|
+
reject(error: Error): void;
|
|
12
|
+
}
|
|
13
|
+
export interface PipelineWriteableStream {
|
|
14
|
+
isPipeline: true;
|
|
15
|
+
write(data: string | Buffer): unknown;
|
|
16
|
+
destination: {
|
|
17
|
+
redis: {
|
|
18
|
+
stream: NetStream;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare type WriteableStream = NetStream | PipelineWriteableStream;
|
|
23
|
+
export interface CommandItem {
|
|
24
|
+
command: Respondable;
|
|
25
|
+
stream: WriteableStream;
|
|
26
|
+
select: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ScanStreamOptions {
|
|
29
|
+
match?: string;
|
|
30
|
+
type?: string;
|
|
31
|
+
count?: number;
|
|
32
|
+
noValues?: boolean;
|
|
33
|
+
}
|
package/built/types.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Command from "../Command";
|
|
2
|
+
import { WriteableStream } from "../types";
|
|
3
|
+
import RedisCommander, { ClientContext } from "./RedisCommander";
|
|
4
|
+
export interface CommanderOptions {
|
|
5
|
+
keyPrefix?: string | undefined;
|
|
6
|
+
showFriendlyErrorStack?: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
declare class Commander<Context extends ClientContext = {
|
|
9
|
+
type: "default";
|
|
10
|
+
}> {
|
|
11
|
+
options: CommanderOptions;
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
scriptsSet: {};
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
|
+
addedBuiltinSet: Set<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Return supported builtin commands
|
|
22
|
+
*/
|
|
23
|
+
getBuiltinCommands(): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Create a builtin command
|
|
26
|
+
*/
|
|
27
|
+
createBuiltinCommand(commandName: string): {
|
|
28
|
+
string: any;
|
|
29
|
+
buffer: any;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create add builtin command
|
|
33
|
+
*/
|
|
34
|
+
addBuiltinCommand(commandName: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Define a custom command using lua script
|
|
37
|
+
*/
|
|
38
|
+
defineCommand(name: string, definition: {
|
|
39
|
+
lua: string;
|
|
40
|
+
numberOfKeys?: number;
|
|
41
|
+
readOnly?: boolean;
|
|
42
|
+
}): void;
|
|
43
|
+
/**
|
|
44
|
+
* @ignore
|
|
45
|
+
*/
|
|
46
|
+
sendCommand(command: Command, stream?: WriteableStream, node?: unknown): unknown;
|
|
47
|
+
}
|
|
48
|
+
interface Commander<Context> extends RedisCommander<Context> {
|
|
49
|
+
}
|
|
50
|
+
export default Commander;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const commands_1 = require("@ioredis/commands");
|
|
4
|
+
const autoPipelining_1 = require("../autoPipelining");
|
|
5
|
+
const Command_1 = require("../Command");
|
|
6
|
+
const Script_1 = require("../Script");
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
class Commander {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.options = {};
|
|
11
|
+
/**
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
this.scriptsSet = {};
|
|
15
|
+
/**
|
|
16
|
+
* @ignore
|
|
17
|
+
*/
|
|
18
|
+
this.addedBuiltinSet = new Set();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return supported builtin commands
|
|
22
|
+
*/
|
|
23
|
+
getBuiltinCommands() {
|
|
24
|
+
return commands.slice(0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a builtin command
|
|
28
|
+
*/
|
|
29
|
+
createBuiltinCommand(commandName) {
|
|
30
|
+
return {
|
|
31
|
+
string: generateFunction(null, commandName, "utf8"),
|
|
32
|
+
buffer: generateFunction(null, commandName, null),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create add builtin command
|
|
37
|
+
*/
|
|
38
|
+
addBuiltinCommand(commandName) {
|
|
39
|
+
this.addedBuiltinSet.add(commandName);
|
|
40
|
+
this[commandName] = generateFunction(commandName, commandName, "utf8");
|
|
41
|
+
this[commandName + "Buffer"] = generateFunction(commandName + "Buffer", commandName, null);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Define a custom command using lua script
|
|
45
|
+
*/
|
|
46
|
+
defineCommand(name, definition) {
|
|
47
|
+
const script = new Script_1.default(definition.lua, definition.numberOfKeys, this.options.keyPrefix, definition.readOnly);
|
|
48
|
+
this.scriptsSet[name] = script;
|
|
49
|
+
this[name] = generateScriptingFunction(name, name, script, "utf8");
|
|
50
|
+
this[name + "Buffer"] = generateScriptingFunction(name + "Buffer", name, script, null);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
sendCommand(command, stream, node) {
|
|
56
|
+
throw new Error('"sendCommand" is not implemented');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const commands = commands_1.list.filter((command) => command !== "monitor");
|
|
60
|
+
commands.push("sentinel");
|
|
61
|
+
commands.forEach(function (commandName) {
|
|
62
|
+
Commander.prototype[commandName] = generateFunction(commandName, commandName, "utf8");
|
|
63
|
+
Commander.prototype[commandName + "Buffer"] = generateFunction(commandName + "Buffer", commandName, null);
|
|
64
|
+
});
|
|
65
|
+
Commander.prototype.call = generateFunction("call", "utf8");
|
|
66
|
+
Commander.prototype.callBuffer = generateFunction("callBuffer", null);
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
Commander.prototype.send_command = Commander.prototype.call;
|
|
69
|
+
function generateFunction(functionName, _commandName, _encoding) {
|
|
70
|
+
if (typeof _encoding === "undefined") {
|
|
71
|
+
_encoding = _commandName;
|
|
72
|
+
_commandName = null;
|
|
73
|
+
}
|
|
74
|
+
return function (...args) {
|
|
75
|
+
const commandName = (_commandName || args.shift());
|
|
76
|
+
let callback = args[args.length - 1];
|
|
77
|
+
if (typeof callback === "function") {
|
|
78
|
+
args.pop();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
callback = undefined;
|
|
82
|
+
}
|
|
83
|
+
const options = {
|
|
84
|
+
errorStack: this.options.showFriendlyErrorStack ? new Error() : undefined,
|
|
85
|
+
keyPrefix: this.options.keyPrefix,
|
|
86
|
+
replyEncoding: _encoding,
|
|
87
|
+
};
|
|
88
|
+
// No auto pipeline, use regular command sending
|
|
89
|
+
if (!(0, autoPipelining_1.shouldUseAutoPipelining)(this, functionName, commandName)) {
|
|
90
|
+
return this.sendCommand(
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
new Command_1.default(commandName, args, options, callback));
|
|
93
|
+
}
|
|
94
|
+
// Create a new pipeline and make sure it's scheduled
|
|
95
|
+
return (0, autoPipelining_1.executeWithAutoPipelining)(this, functionName, commandName,
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
args, callback);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function generateScriptingFunction(functionName, commandName, script, encoding) {
|
|
101
|
+
return function (...args) {
|
|
102
|
+
const callback = typeof args[args.length - 1] === "function" ? args.pop() : undefined;
|
|
103
|
+
const options = {
|
|
104
|
+
replyEncoding: encoding,
|
|
105
|
+
};
|
|
106
|
+
if (this.options.showFriendlyErrorStack) {
|
|
107
|
+
options.errorStack = new Error();
|
|
108
|
+
}
|
|
109
|
+
// No auto pipeline, use regular command sending
|
|
110
|
+
if (!(0, autoPipelining_1.shouldUseAutoPipelining)(this, functionName, commandName)) {
|
|
111
|
+
return script.execute(this, args, options, callback);
|
|
112
|
+
}
|
|
113
|
+
// Create a new pipeline and make sure it's scheduled
|
|
114
|
+
return (0, autoPipelining_1.executeWithAutoPipelining)(this, functionName, commandName, args, callback);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
exports.default = Commander;
|