New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@node-redis/client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-redis/client - npm Package Compare versions

Comparing version 1.0.0-rc.0 to 1.0.0

10

CHANGELOG.md
# Changelog
## v4.0.0
## v4.0.0 - 24 Nov, 2021

@@ -20,6 +20,6 @@ This version is a major change and refactor, adding modern JavaScript capabilities and multiple breaking changes. See the [migration guide](../../docs/v3-to-v4.md) for tips on how to upgrade.

- Added built-in TypeScript declaration files enabling code completion
- Added support for [clustering](../../.github/README.md#cluster)
- Added idiomatic arguments and responses to [Redis commands](../../.github/README.md#redis-commands)
- Added full support for [Lua Scripts](../../.github/README.md#lua-scripts)
- Added support for [SCAN iterators](../../.github/README.md#scan-iterator)
- Added support for [clustering](../../README.md#cluster)
- Added idiomatic arguments and responses to [Redis commands](../../README.md#redis-commands)
- Added full support for [Lua Scripts](../../README.md#lua-scripts)
- Added support for [SCAN iterators](../../README.md#scan-iterator)
- Added the ability to extend Node Redis with Redis Module commands

@@ -26,0 +26,0 @@

@@ -16,4 +16,4 @@ /// <reference types="node" />

}
export declare type PubSubListener = (message: string, channel: string) => unknown;
export declare type PubSubListenersMap = Map<string, Set<PubSubListener>>;
declare type PubSubArgumentTypes = Buffer | string;
export declare type PubSubListener<BUFFER_MODE extends boolean = false, T = BUFFER_MODE extends true ? Buffer : string> = (message: T, channel: T) => unknown;
export default class RedisCommandsQueue {

@@ -23,4 +23,4 @@ #private;

addCommand<T = RedisCommandRawReply>(args: RedisCommandArguments, options?: QueueCommandOptions, bufferMode?: boolean): Promise<T>;
subscribe(command: PubSubSubscribeCommands, channels: string | Array<string>, listener: PubSubListener): Promise<void>;
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener): Promise<void>;
subscribe<T extends boolean>(command: PubSubSubscribeCommands, channels: PubSubArgumentTypes | Array<PubSubArgumentTypes>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>;
unsubscribe<T extends boolean>(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>;
resubscribe(): Promise<any> | undefined;

@@ -32,1 +32,2 @@ getCommandToSend(): RedisCommandArguments | undefined;

}
export {};

@@ -13,3 +13,3 @@ "use strict";

};
var _RedisCommandsQueue_instances, _a, _RedisCommandsQueue_flushQueue, _RedisCommandsQueue_emitPubSubMessage, _RedisCommandsQueue_maxLength, _RedisCommandsQueue_waitingToBeSent, _RedisCommandsQueue_waitingForReply, _RedisCommandsQueue_pubSubState, _RedisCommandsQueue_pubSubListeners, _RedisCommandsQueue_parser, _RedisCommandsQueue_chainInExecution, _RedisCommandsQueue_pushPubSubCommand, _RedisCommandsQueue_shiftWaitingForReply;
var _RedisCommandsQueue_instances, _a, _RedisCommandsQueue_flushQueue, _RedisCommandsQueue_emitPubSubMessage, _RedisCommandsQueue_maxLength, _RedisCommandsQueue_waitingToBeSent, _RedisCommandsQueue_waitingForReply, _RedisCommandsQueue_pubSubState, _RedisCommandsQueue_PUB_SUB_MESSAGES, _RedisCommandsQueue_parser, _RedisCommandsQueue_chainInExecution, _RedisCommandsQueue_initiatePubSubState, _RedisCommandsQueue_pushPubSubCommand, _RedisCommandsQueue_shiftWaitingForReply;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -39,26 +39,21 @@ exports.PubSubUnsubscribeCommands = exports.PubSubSubscribeCommands = void 0;

_RedisCommandsQueue_waitingForReply.set(this, new LinkedList());
_RedisCommandsQueue_pubSubState.set(this, {
subscribing: 0,
subscribed: 0,
unsubscribing: 0
});
_RedisCommandsQueue_pubSubListeners.set(this, {
channels: new Map(),
patterns: new Map()
});
_RedisCommandsQueue_pubSubState.set(this, void 0);
_RedisCommandsQueue_parser.set(this, new RedisParser({
returnReply: (reply) => {
if ((__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribing || __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribed) && Array.isArray(reply)) {
switch (reply[0]) {
case 'message':
return __classPrivateFieldGet(RedisCommandsQueue, _a, "m", _RedisCommandsQueue_emitPubSubMessage).call(RedisCommandsQueue, __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").channels.get(reply[1]), reply[2], reply[1]);
case 'pmessage':
return __classPrivateFieldGet(RedisCommandsQueue, _a, "m", _RedisCommandsQueue_emitPubSubMessage).call(RedisCommandsQueue, __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").patterns.get(reply[1]), reply[3], reply[2]);
case 'subscribe':
case 'psubscribe':
if (--__classPrivateFieldGet(this, _RedisCommandsQueue_waitingForReply, "f").head.value.channelsCounter === 0) {
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_shiftWaitingForReply).call(this).resolve();
}
return;
if (__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f") && Array.isArray(reply)) {
if (__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).message.equals(reply[0])) {
return __classPrivateFieldGet(RedisCommandsQueue, _a, "m", _RedisCommandsQueue_emitPubSubMessage).call(RedisCommandsQueue, __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.channels, reply[2], reply[1]);
}
else if (__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).pMessage.equals(reply[0])) {
return __classPrivateFieldGet(RedisCommandsQueue, _a, "m", _RedisCommandsQueue_emitPubSubMessage).call(RedisCommandsQueue, __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.patterns, reply[3], reply[2], reply[1]);
}
else if (__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).subscribe.equals(reply[0]) ||
__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).pSubscribe.equals(reply[0]) ||
__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).unsubscribe.equals(reply[0]) ||
__classPrivateFieldGet(RedisCommandsQueue, _a, "f", _RedisCommandsQueue_PUB_SUB_MESSAGES).pUnsubscribe.equals(reply[0])) {
if (--__classPrivateFieldGet(this, _RedisCommandsQueue_waitingForReply, "f").head.value.channelsCounter === 0) {
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_shiftWaitingForReply).call(this).resolve();
}
return;
}
}

@@ -74,3 +69,3 @@ __classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_shiftWaitingForReply).call(this).resolve(reply);

var _b;
if (__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribing || __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribed) {
if (__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")) {
return Promise.reject(new Error('Cannot send commands in PubSub mode'));

@@ -90,3 +85,3 @@ }

resolve,
reject,
reject
});

@@ -115,11 +110,17 @@ if (options === null || options === void 0 ? void 0 : options.signal) {

}
subscribe(command, channels, listener) {
const channelsToSubscribe = [], listeners = command === PubSubSubscribeCommands.SUBSCRIBE ? __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").channels : __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").patterns;
subscribe(command, channels, listener, bufferMode) {
const pubSubState = __classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_initiatePubSubState).call(this), channelsToSubscribe = [], listenersMap = command === PubSubSubscribeCommands.SUBSCRIBE ? pubSubState.listeners.channels : pubSubState.listeners.patterns;
for (const channel of (Array.isArray(channels) ? channels : [channels])) {
if (listeners.has(channel)) {
listeners.get(channel).add(listener);
continue;
const channelString = typeof channel === 'string' ? channel : channel.toString();
let listeners = listenersMap.get(channelString);
if (!listeners) {
listeners = {
buffers: new Set(),
strings: new Set()
};
listenersMap.set(channelString, listeners);
channelsToSubscribe.push(channel);
}
listeners.set(channel, new Set([listener]));
channelsToSubscribe.push(channel);
// https://github.com/microsoft/TypeScript/issues/23132
(bufferMode ? listeners.buffers : listeners.strings).add(listener);
}

@@ -131,4 +132,9 @@ if (!channelsToSubscribe.length) {

}
unsubscribe(command, channels, listener) {
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").channels : __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").patterns;
unsubscribe(command, channels, listener, bufferMode) {
if (!__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")) {
return Promise.resolve();
}
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ?
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.channels :
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.patterns;
if (!channels) {

@@ -141,10 +147,14 @@ const size = listeners.size;

for (const channel of (Array.isArray(channels) ? channels : [channels])) {
const set = listeners.get(channel);
if (!set)
const sets = listeners.get(channel);
if (!sets)
continue;
let shouldUnsubscribe = !listener;
let shouldUnsubscribe;
if (listener) {
set.delete(listener);
shouldUnsubscribe = set.size === 0;
// https://github.com/microsoft/TypeScript/issues/23132
(bufferMode ? sets.buffers : sets.strings).delete(listener);
shouldUnsubscribe = !sets.buffers.size && !sets.strings.size;
}
else {
shouldUnsubscribe = true;
}
if (shouldUnsubscribe) {

@@ -161,10 +171,9 @@ channelsToUnsubscribe.push(channel);

resubscribe() {
if (!__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribed && !__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribing) {
if (!__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")) {
return;
}
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribed = __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribing = 0;
// TODO: acl error on one channel/pattern will reject the whole command
return Promise.all([
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_pushPubSubCommand).call(this, PubSubSubscribeCommands.SUBSCRIBE, [...__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").channels.keys()]),
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_pushPubSubCommand).call(this, PubSubSubscribeCommands.PSUBSCRIBE, [...__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubListeners, "f").patterns.keys()])
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_pushPubSubCommand).call(this, PubSubSubscribeCommands.SUBSCRIBE, [...__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.channels.keys()]),
__classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_pushPubSubCommand).call(this, PubSubSubscribeCommands.PSUBSCRIBE, [...__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").listeners.patterns.keys()])
]);

@@ -186,4 +195,5 @@ }

parseResponse(data) {
var _b;
__classPrivateFieldGet(this, _RedisCommandsQueue_parser, "f").setReturnBuffers(!!((_b = __classPrivateFieldGet(this, _RedisCommandsQueue_waitingForReply, "f").head) === null || _b === void 0 ? void 0 : _b.value.bufferMode));
var _b, _c;
__classPrivateFieldGet(this, _RedisCommandsQueue_parser, "f").setReturnBuffers(!!((_b = __classPrivateFieldGet(this, _RedisCommandsQueue_waitingForReply, "f").head) === null || _b === void 0 ? void 0 : _b.value.bufferMode) ||
!!((_c = __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")) === null || _c === void 0 ? void 0 : _c.subscribed));
__classPrivateFieldGet(this, _RedisCommandsQueue_parser, "f").execute(data);

@@ -208,13 +218,31 @@ }

exports.default = RedisCommandsQueue;
_a = RedisCommandsQueue, _RedisCommandsQueue_maxLength = new WeakMap(), _RedisCommandsQueue_waitingToBeSent = new WeakMap(), _RedisCommandsQueue_waitingForReply = new WeakMap(), _RedisCommandsQueue_pubSubState = new WeakMap(), _RedisCommandsQueue_pubSubListeners = new WeakMap(), _RedisCommandsQueue_parser = new WeakMap(), _RedisCommandsQueue_chainInExecution = new WeakMap(), _RedisCommandsQueue_instances = new WeakSet(), _RedisCommandsQueue_flushQueue = function _RedisCommandsQueue_flushQueue(queue, err) {
_a = RedisCommandsQueue, _RedisCommandsQueue_maxLength = new WeakMap(), _RedisCommandsQueue_waitingToBeSent = new WeakMap(), _RedisCommandsQueue_waitingForReply = new WeakMap(), _RedisCommandsQueue_pubSubState = new WeakMap(), _RedisCommandsQueue_parser = new WeakMap(), _RedisCommandsQueue_chainInExecution = new WeakMap(), _RedisCommandsQueue_instances = new WeakSet(), _RedisCommandsQueue_flushQueue = function _RedisCommandsQueue_flushQueue(queue, err) {
while (queue.length) {
queue.shift().reject(err);
}
}, _RedisCommandsQueue_emitPubSubMessage = function _RedisCommandsQueue_emitPubSubMessage(listeners, message, channel) {
for (const listener of listeners) {
}, _RedisCommandsQueue_emitPubSubMessage = function _RedisCommandsQueue_emitPubSubMessage(listenersMap, message, channel, pattern) {
const keyString = (pattern || channel).toString(), listeners = listenersMap.get(keyString);
for (const listener of listeners.buffers) {
listener(message, channel);
}
if (!listeners.strings.size)
return;
const messageString = message.toString(), channelString = pattern ? channel.toString() : keyString;
for (const listener of listeners.strings) {
listener(messageString, channelString);
}
}, _RedisCommandsQueue_initiatePubSubState = function _RedisCommandsQueue_initiatePubSubState() {
var _b;
return __classPrivateFieldSet(this, _RedisCommandsQueue_pubSubState, (_b = __classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")) !== null && _b !== void 0 ? _b : {
subscribed: 0,
subscribing: 0,
unsubscribing: 0,
listeners: {
channels: new Map(),
patterns: new Map()
}
}, "f");
}, _RedisCommandsQueue_pushPubSubCommand = function _RedisCommandsQueue_pushPubSubCommand(command, channels) {
return new Promise((resolve, reject) => {
const isSubscribe = command === PubSubSubscribeCommands.SUBSCRIBE || command === PubSubSubscribeCommands.PSUBSCRIBE, inProgressKey = isSubscribe ? 'subscribing' : 'unsubscribing', commandArgs = [command];
const pubSubState = __classPrivateFieldGet(this, _RedisCommandsQueue_instances, "m", _RedisCommandsQueue_initiatePubSubState).call(this), isSubscribe = command === PubSubSubscribeCommands.SUBSCRIBE || command === PubSubSubscribeCommands.PSUBSCRIBE, inProgressKey = isSubscribe ? 'subscribing' : 'unsubscribing', commandArgs = [command];
let channelsCounter;

@@ -228,13 +256,22 @@ if (typeof channels === 'number') { // unsubscribe only

}
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")[inProgressKey] += channelsCounter;
pubSubState[inProgressKey] += channelsCounter;
__classPrivateFieldGet(this, _RedisCommandsQueue_waitingToBeSent, "f").push({
args: commandArgs,
channelsCounter,
bufferMode: true,
resolve: () => {
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")[inProgressKey] -= channelsCounter;
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f").subscribed += channelsCounter * (isSubscribe ? 1 : -1);
pubSubState[inProgressKey] -= channelsCounter;
if (isSubscribe) {
pubSubState.subscribed += channelsCounter;
}
else {
pubSubState.subscribed -= channelsCounter;
if (!pubSubState.subscribed && !pubSubState.subscribing && !pubSubState.subscribed) {
__classPrivateFieldSet(this, _RedisCommandsQueue_pubSubState, undefined, "f");
}
}
resolve();
},
reject: () => {
__classPrivateFieldGet(this, _RedisCommandsQueue_pubSubState, "f")[inProgressKey] -= channelsCounter;
pubSubState[inProgressKey] -= channelsCounter * (isSubscribe ? 1 : -1);
reject();

@@ -250,1 +287,9 @@ }

};
_RedisCommandsQueue_PUB_SUB_MESSAGES = { value: {
message: Buffer.from('message'),
pMessage: Buffer.from('pmessage'),
subscribe: Buffer.from('subscribe'),
pSubscribe: Buffer.from('psubscribe'),
unsubscribe: Buffer.from('unsunscribe'),
pUnsubscribe: Buffer.from('punsubscribe')
} };

@@ -67,10 +67,10 @@ /// <reference types="node" />

};
SUBSCRIBE(channels: string | Array<string>, listener: PubSubListener): Promise<void>;
subscribe: (channels: string | Array<string>, listener: PubSubListener) => Promise<void>;
PSUBSCRIBE(patterns: string | Array<string>, listener: PubSubListener): Promise<void>;
pSubscribe: (patterns: string | Array<string>, listener: PubSubListener) => Promise<void>;
UNSUBSCRIBE(channels?: string | Array<string>, listener?: PubSubListener): Promise<void>;
unsubscribe: (channels?: string | string[] | undefined, listener?: PubSubListener | undefined) => Promise<void>;
PUNSUBSCRIBE(patterns?: string | Array<string>, listener?: PubSubListener): Promise<void>;
pUnsubscribe: (patterns?: string | string[] | undefined, listener?: PubSubListener | undefined) => Promise<void>;
SUBSCRIBE<T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>;
subscribe: <T extends boolean = false>(channels: string | Array<string>, listener: PubSubListener<T, T extends true ? Buffer : string>, bufferMode?: T | undefined) => Promise<void>;
PSUBSCRIBE<T extends boolean = false>(patterns: string | Array<string>, listener: PubSubListener<T>, bufferMode?: T): Promise<void>;
pSubscribe: <T extends boolean = false>(patterns: string | Array<string>, listener: PubSubListener<T, T extends true ? Buffer : string>, bufferMode?: T | undefined) => Promise<void>;
UNSUBSCRIBE<T extends boolean = false>(channels?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>;
unsubscribe: <T extends boolean = false>(channels?: string | string[] | undefined, listener?: PubSubListener<T, T extends true ? Buffer : string> | undefined, bufferMode?: T | undefined) => Promise<void>;
PUNSUBSCRIBE<T extends boolean = false>(patterns?: string | Array<string>, listener?: PubSubListener<T>, bufferMode?: T): Promise<void>;
pUnsubscribe: <T extends boolean = false>(patterns?: string | string[] | undefined, listener?: PubSubListener<T, T extends true ? Buffer : string> | undefined, bufferMode?: T | undefined) => Promise<void>;
QUIT(): Promise<void>;

@@ -77,0 +77,0 @@ quit: () => Promise<void>;

@@ -199,13 +199,13 @@ "use strict";

}
SUBSCRIBE(channels, listener) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribe).call(this, commands_queue_1.PubSubSubscribeCommands.SUBSCRIBE, channels, listener);
SUBSCRIBE(channels, listener, bufferMode) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribe).call(this, commands_queue_1.PubSubSubscribeCommands.SUBSCRIBE, channels, listener, bufferMode);
}
PSUBSCRIBE(patterns, listener) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribe).call(this, commands_queue_1.PubSubSubscribeCommands.PSUBSCRIBE, patterns, listener);
PSUBSCRIBE(patterns, listener, bufferMode) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribe).call(this, commands_queue_1.PubSubSubscribeCommands.PSUBSCRIBE, patterns, listener, bufferMode);
}
UNSUBSCRIBE(channels, listener) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unsubscribe).call(this, commands_queue_1.PubSubUnsubscribeCommands.UNSUBSCRIBE, channels, listener);
UNSUBSCRIBE(channels, listener, bufferMode) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unsubscribe).call(this, commands_queue_1.PubSubUnsubscribeCommands.UNSUBSCRIBE, channels, listener, bufferMode);
}
PUNSUBSCRIBE(patterns, listener) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unsubscribe).call(this, commands_queue_1.PubSubUnsubscribeCommands.PUNSUBSCRIBE, patterns, listener);
PUNSUBSCRIBE(patterns, listener, bufferMode) {
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unsubscribe).call(this, commands_queue_1.PubSubUnsubscribeCommands.PUNSUBSCRIBE, patterns, listener, bufferMode);
}

@@ -399,8 +399,8 @@ QUIT() {

return promise;
}, _RedisClient_subscribe = function _RedisClient_subscribe(command, channels, listener) {
const promise = __classPrivateFieldGet(this, _RedisClient_queue, "f").subscribe(command, channels, listener);
}, _RedisClient_subscribe = function _RedisClient_subscribe(command, channels, listener, bufferMode) {
const promise = __classPrivateFieldGet(this, _RedisClient_queue, "f").subscribe(command, channels, listener, bufferMode);
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_tick).call(this);
return promise;
}, _RedisClient_unsubscribe = function _RedisClient_unsubscribe(command, channels, listener) {
const promise = __classPrivateFieldGet(this, _RedisClient_queue, "f").unsubscribe(command, channels, listener);
}, _RedisClient_unsubscribe = function _RedisClient_unsubscribe(command, channels, listener, bufferMode) {
const promise = __classPrivateFieldGet(this, _RedisClient_queue, "f").unsubscribe(command, channels, listener, bufferMode);
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_tick).call(this);

@@ -407,0 +407,0 @@ return promise;

@@ -14,3 +14,3 @@ /// <reference types="node" />

connect(): Promise<void>;
discover(startWith: RedisClientType<M, S>): Promise<void>;
rediscover(startWith: RedisClientType<M, S>): Promise<void>;
getSlotMaster(slot: number): ClusterNode<M, S>;

@@ -17,0 +17,0 @@ getClient(firstKey?: string | Buffer, isReadonly?: boolean): RedisClientType<M, S>;

@@ -13,3 +13,3 @@ "use strict";

};
var _RedisClusterSlots_instances, _RedisClusterSlots_options, _RedisClusterSlots_Client, _RedisClusterSlots_onError, _RedisClusterSlots_nodeByUrl, _RedisClusterSlots_slots, _RedisClusterSlots_discoverNodes, _RedisClusterSlots_reset, _RedisClusterSlots_clientOptionsDefaults, _RedisClusterSlots_initiateClientForNode, _RedisClusterSlots_slotClientIterator, _RedisClusterSlots_getSlotClient, _RedisClusterSlots_randomClientIterator, _RedisClusterSlots_getRandomClient;
var _RedisClusterSlots_instances, _RedisClusterSlots_options, _RedisClusterSlots_Client, _RedisClusterSlots_onError, _RedisClusterSlots_nodeByUrl, _RedisClusterSlots_slots, _RedisClusterSlots_discoverNodes, _RedisClusterSlots_runningRediscoverPromise, _RedisClusterSlots_rediscover, _RedisClusterSlots_reset, _RedisClusterSlots_clientOptionsDefaults, _RedisClusterSlots_initiateClient, _RedisClusterSlots_initiateClientForNode, _RedisClusterSlots_slotClientIterator, _RedisClusterSlots_getSlotClient, _RedisClusterSlots_randomClientIterator, _RedisClusterSlots_getRandomClient;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -29,2 +29,3 @@ const client_1 = require("../client");

_RedisClusterSlots_slots.set(this, []);
_RedisClusterSlots_runningRediscoverPromise.set(this, void 0);
_RedisClusterSlots_randomClientIterator.set(this, void 0);

@@ -42,12 +43,8 @@ __classPrivateFieldSet(this, _RedisClusterSlots_options, options, "f");

}
async discover(startWith) {
if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverNodes).call(this, startWith.options))
return;
for (const { client } of __classPrivateFieldGet(this, _RedisClusterSlots_nodeByUrl, "f").values()) {
if (client === startWith)
continue;
if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverNodes).call(this, client.options))
return;
async rediscover(startWith) {
if (!__classPrivateFieldGet(this, _RedisClusterSlots_runningRediscoverPromise, "f")) {
__classPrivateFieldSet(this, _RedisClusterSlots_runningRediscoverPromise, __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_rediscover).call(this, startWith)
.finally(() => __classPrivateFieldSet(this, _RedisClusterSlots_runningRediscoverPromise, undefined, "f")), "f");
}
throw new Error('None of the cluster nodes is available');
return __classPrivateFieldGet(this, _RedisClusterSlots_runningRediscoverPromise, "f");
}

@@ -87,4 +84,4 @@ getSlotMaster(slot) {

exports.default = RedisClusterSlots;
_RedisClusterSlots_options = new WeakMap(), _RedisClusterSlots_Client = new WeakMap(), _RedisClusterSlots_onError = new WeakMap(), _RedisClusterSlots_nodeByUrl = new WeakMap(), _RedisClusterSlots_slots = new WeakMap(), _RedisClusterSlots_randomClientIterator = new WeakMap(), _RedisClusterSlots_instances = new WeakSet(), _RedisClusterSlots_discoverNodes = async function _RedisClusterSlots_discoverNodes(clientOptions) {
const client = new (__classPrivateFieldGet(this, _RedisClusterSlots_Client, "f"))(clientOptions);
_RedisClusterSlots_options = new WeakMap(), _RedisClusterSlots_Client = new WeakMap(), _RedisClusterSlots_onError = new WeakMap(), _RedisClusterSlots_nodeByUrl = new WeakMap(), _RedisClusterSlots_slots = new WeakMap(), _RedisClusterSlots_runningRediscoverPromise = new WeakMap(), _RedisClusterSlots_randomClientIterator = new WeakMap(), _RedisClusterSlots_instances = new WeakSet(), _RedisClusterSlots_discoverNodes = async function _RedisClusterSlots_discoverNodes(clientOptions) {
const client = __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiateClient).call(this, clientOptions);
await client.connect();

@@ -104,2 +101,12 @@ try {

}
}, _RedisClusterSlots_rediscover = async function _RedisClusterSlots_rediscover(startWith) {
if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverNodes).call(this, startWith.options))
return;
for (const { client } of __classPrivateFieldGet(this, _RedisClusterSlots_nodeByUrl, "f").values()) {
if (client === startWith)
continue;
if (await __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_discoverNodes).call(this, client.options))
return;
}
throw new Error('None of the cluster nodes is available');
}, _RedisClusterSlots_reset = async function _RedisClusterSlots_reset(masters) {

@@ -134,6 +141,9 @@ // Override this.#slots and add not existing clients to this.#nodeByUrl

const merged = Object.assign({}, __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults, options);
if (options.socket && __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket) {
if ((options === null || options === void 0 ? void 0 : options.socket) && __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket) {
Object.assign({}, __classPrivateFieldGet(this, _RedisClusterSlots_options, "f").defaults.socket, options.socket);
}
return merged;
}, _RedisClusterSlots_initiateClient = function _RedisClusterSlots_initiateClient(options) {
return new (__classPrivateFieldGet(this, _RedisClusterSlots_Client, "f"))(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_clientOptionsDefaults).call(this, options))
.on('error', __classPrivateFieldGet(this, _RedisClusterSlots_onError, "f"));
}, _RedisClusterSlots_initiateClientForNode = function _RedisClusterSlots_initiateClientForNode(nodeData, readonly, clientsInUse, promises) {

@@ -146,3 +156,3 @@ const url = `${nodeData.host}:${nodeData.port}`;

id: nodeData.id,
client: new (__classPrivateFieldGet(this, _RedisClusterSlots_Client, "f"))(__classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_clientOptionsDefaults).call(this, {
client: __classPrivateFieldGet(this, _RedisClusterSlots_instances, "m", _RedisClusterSlots_initiateClient).call(this, {
socket: {

@@ -153,3 +163,3 @@ host: nodeData.host,

readonly
}))
})
};

@@ -156,0 +166,0 @@ promises.push(node.client.connect());

@@ -125,3 +125,3 @@ "use strict";

if (!node) {
await __classPrivateFieldGet(this, _RedisCluster_slots, "f").discover(client);
await __classPrivateFieldGet(this, _RedisCluster_slots, "f").rediscover(client);
node = __classPrivateFieldGet(this, _RedisCluster_slots, "f").getNodeByUrl(url);

@@ -136,3 +136,3 @@ if (!node) {

else if (err.message.startsWith('MOVED')) {
await __classPrivateFieldGet(this, _RedisCluster_slots, "f").discover(client);
await __classPrivateFieldGet(this, _RedisCluster_slots, "f").rediscover(client);
return true;

@@ -139,0 +139,0 @@ }

@@ -9,3 +9,3 @@ export declare function transformArguments(): Array<string>;

port: number;
cport: number;
cport: number | null;
}

@@ -12,0 +12,0 @@ export interface RedisClusterReplicaNode extends RedisClusterNodeTransformedUrl {

@@ -61,3 +61,10 @@ "use strict";

function transformNodeUrl(url) {
const indexOfColon = url.indexOf(':'), indexOfAt = url.indexOf('@', indexOfColon);
const indexOfColon = url.indexOf(':'), indexOfAt = url.indexOf('@', indexOfColon), host = url.substring(0, indexOfColon);
if (indexOfAt === -1) {
return {
host,
port: Number(url.substring(indexOfColon + 1)),
cport: null
};
}
return {

@@ -64,0 +71,0 @@ host: url.substring(0, indexOfColon),

@@ -1,4 +0,3 @@

export declare const FIRST_KEY_INDEX = 1;
export declare const IS_READ_ONLY = true;
export declare function transformArguments(key: string, element: string): Array<string>;
export declare function transformArguments(key: string, index: number): Array<string>;
export declare function transformReply(): string | null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
exports.transformArguments = exports.IS_READ_ONLY = void 0;
exports.IS_READ_ONLY = true;
function transformArguments(key, element) {
return ['LINDEX', key, element];
function transformArguments(key, index) {
return ['LINDEX', key, index.toString()];
}
exports.transformArguments = transformArguments;

@@ -1,2 +0,4 @@

export declare function transformArguments(channel: string, message: string): Array<string>;
/// <reference types="node" />
import { RedisCommandArguments } from '.';
export declare function transformArguments(channel: string | Buffer, message: string | Buffer): RedisCommandArguments;
export declare function transformReply(): number;
{
"name": "@node-redis/client",
"version": "1.0.0-rc.0",
"version": "1.0.0",
"license": "MIT",

@@ -22,3 +22,3 @@ "main": "./dist/index.js",

"@node-redis/test-utils": "*",
"@types/node": "^16.11.7",
"@types/node": "^16.11.10",
"@types/redis-parser": "^3.0.0",

@@ -29,12 +29,12 @@ "@types/sinon": "^10.0.6",

"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.2.0",
"eslint": "^8.3.0",
"nyc": "^15.1.0",
"release-it": "^14.11.7",
"release-it": "^14.11.8",
"sinon": "^12.0.1",
"source-map-support": "^0.5.20",
"source-map-support": "^0.5.21",
"ts-node": "^10.4.0",
"typedoc": "^0.22.9",
"typedoc": "^0.22.10",
"typedoc-github-wiki-theme": "^0.6.0",
"typedoc-plugin-markdown": "^3.11.6",
"typescript": "^4.4.4"
"typedoc-plugin-markdown": "^3.11.7",
"typescript": "^4.5.2"
},

@@ -41,0 +41,0 @@ "engines": {

# @node-redis/client
The sources and docs for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.
The source code and documentation for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc