Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function tryConnection(random?: boolean, asking?: string) {
if (_this.status === "end") {
command.reject(new AbortError("Cluster is ended."));
return;
}
let redis;
if (_this.status === "ready" || command.name === "cluster") {
if (node && node.redis) {
redis = node.redis;
} else if (
Command.checkFlag("ENTER_SUBSCRIBER_MODE", command.name) ||
Command.checkFlag("EXIT_SUBSCRIBER_MODE", command.name)
) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError("No subscriber for the cluster"));
return;
}
} else {
function tryConnection(random?: boolean, asking?: string) {
if (_this.status === "end") {
command.reject(new AbortError("Cluster is ended."));
return;
}
let redis;
if (_this.status === "ready" || command.name === "cluster") {
if (node && node.redis) {
redis = node.redis;
} else if (
Command.checkFlag("ENTER_SUBSCRIBER_MODE", command.name) ||
Command.checkFlag("EXIT_SUBSCRIBER_MODE", command.name)
) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError("No subscriber for the cluster"));
return;
}
} else {
if (!random) {
if (typeof targetSlot === "number" && _this.slots[targetSlot]) {
const nodeKeys = _this.slots[targetSlot];
if (typeof to === "function") {
const nodes = nodeKeys.map(function(key) {
return _this.connectionPool.getInstanceByKey(key);
});
redis = to(nodes, command);
if (Array.isArray(redis)) {
redis = sample(redis);
}
if (!redis) {
redis = nodes[0];
function tryConnection(random, asking) {
if (_this.status === 'end') {
command.reject(new AbortError('Cluster is ended.'));
return;
}
var redis;
if (_this.status === 'ready' || (command.name === 'cluster')) {
if (node && node.redis) {
redis = node.redis;
} else if (Command.checkFlag('ENTER_SUBSCRIBER_MODE', command.name) ||
Command.checkFlag('EXIT_SUBSCRIBER_MODE', command.name)) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError('No subscriber for the cluster'));
return;
}
} else {
if (!random) {
if (typeof targetSlot === 'number' && _this.slots[targetSlot]) {
function tryConnection(random, asking) {
if (_this.status === 'end') {
command.reject(new AbortError('Cluster is ended.'));
return;
}
var redis;
if (_this.status === 'ready' || (command.name === 'cluster')) {
if (node && node.redis) {
redis = node.redis;
} else if (Command.checkFlag('ENTER_SUBSCRIBER_MODE', command.name) ||
Command.checkFlag('EXIT_SUBSCRIBER_MODE', command.name)) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError('No subscriber for the cluster'));
return;
}
} else {
if (!random) {
if (typeof targetSlot === 'number' && _this.slots[targetSlot]) {
var nodeKeys = _this.slots[targetSlot];
if (typeof to === 'function') {
var nodes =
nodeKeys
.map(function (key) {
return _this.connectionPool.nodes.all[key];
});
redis = to(nodes, command);
if (Array.isArray(redis)) {
redis = utils.sample(redis);
}