Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sendCommand(command, stream, node) {
if (this.status === "wait") {
this.connect().catch(noop);
}
if (this.status === "end") {
command.reject(new Error(CONNECTION_CLOSED_ERROR_MSG));
return command.promise;
}
let to = this.options.scaleReads;
if (to !== "master") {
const isCommandReadOnly =
commands.exists(command.name) &&
commands.hasFlag(command.name, "readonly");
if (!isCommandReadOnly) {
to = "master";
}
}
let targetSlot = node ? node.slot : command.getSlot();
const ttl = {};
const _this = this;
if (!node && !command.__is_reject_overwritten) {
// eslint-disable-next-line @typescript-eslint/camelcase
command.__is_reject_overwritten = true;
const reject = command.reject;
command.reject = function(err) {
const partialTry = tryConnection.bind(null, true);
_this.handleError(err, ttl, {
this.condition.subscriber &&
!Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", command.name)
) {
command.reject(
new Error(
"Connection in subscriber mode, only subscriber commands may be used"
)
);
return command.promise;
}
var writable =
this.status === "ready" ||
(!stream &&
this.status === "connect" &&
commands.exists(command.name) &&
commands.hasFlag(command.name, "loading"));
if (!this.stream) {
writable = false;
} else if (!this.stream.writable) {
writable = false;
} else if (this.stream._writableState && this.stream._writableState.ended) {
// https://github.com/iojs/io.js/pull/1217
writable = false;
}
if (!writable && !this.options.enableOfflineQueue) {
command.reject(
new Error(
"Stream isn't writeable and enableOfflineQueue options is false"
)
);
private _iterateKeys(
transform: Function = key => key
): Array {
if (typeof this.keys === "undefined") {
this.keys = [];
if (commands.exists(this.name)) {
const keyIndexes = commands.getKeyIndexes(this.name, this.args);
for (const index of keyIndexes) {
this.args[index] = transform(this.args[index]);
this.keys.push(this.args[index] as string | Buffer);
}
}
}
return this.keys;
}
Command.prototype._iterateKeys = function (transform) {
if (typeof this._keys === 'undefined') {
if (typeof transform !== 'function') {
transform = function (key) {
return key;
};
}
this._keys = [];
if (commands.exists(this.name)) {
var keyIndexes = commands.getKeyIndexes(this.name, this.args);
for (var i = 0; i < keyIndexes.length; i++) {
var index = keyIndexes[i];
this.args[index] = transform(this.args[index]);
this._keys.push(this.args[index]);
}
}
}
return this._keys;
};