You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
prepare 4.1.0 (#2111)
* increase test coverage * @node-redis to @redis * ugprade deps * fix benchmark * use 7.0 docker (not rc), update readmes, clean code, fix @-redis import * update readme * fix function in cluster * update docs Co-authored-by: Chayim <chayim@users.noreply.github.com> * Update clustering.md * add subpackages move warning * drop support for node 12 * upgrade deps * fix tsconfig.base.json Co-authored-by: Chayim <chayim@users.noreply.github.com>
This commit is contained in:
@@ -347,10 +347,6 @@ export default class RedisCommandsQueue {
|
||||
return encoded;
|
||||
}
|
||||
|
||||
rejectLastCommand(err: unknown): void {
|
||||
this.#waitingForReply.pop()!.reject(err);
|
||||
}
|
||||
|
||||
onReplyChunk(chunk: Buffer): void {
|
||||
this.#decoder.write(chunk);
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ export const MATH_FUNCTION = {
|
||||
library: {
|
||||
square: {
|
||||
NAME: 'square',
|
||||
IS_READ_ONLY: true,
|
||||
NUMBER_OF_KEYS: 0,
|
||||
transformArguments(number: number): Array<string> {
|
||||
return [number.toString()];
|
||||
@@ -722,8 +723,11 @@ describe('Client', () => {
|
||||
await subscriber.connect();
|
||||
|
||||
try {
|
||||
const listener = spy();
|
||||
await subscriber.subscribe('channel', listener);
|
||||
const channelListener = spy();
|
||||
await subscriber.subscribe('channel', channelListener);
|
||||
|
||||
const patternListener = spy();
|
||||
await subscriber.pSubscribe('channe*', patternListener);
|
||||
|
||||
await Promise.all([
|
||||
once(subscriber, 'error'),
|
||||
@@ -736,7 +740,8 @@ describe('Client', () => {
|
||||
await once(subscriber, 'ready');
|
||||
|
||||
await Promise.all([
|
||||
waitTillBeenCalled(listener),
|
||||
waitTillBeenCalled(channelListener),
|
||||
waitTillBeenCalled(patternListener),
|
||||
publisher.publish('channel', 'message')
|
||||
]);
|
||||
} finally {
|
||||
|
@@ -399,23 +399,25 @@ export default class RedisClient<
|
||||
|
||||
async functionsExecuter<F extends RedisFunction>(
|
||||
fn: F,
|
||||
args: Array<unknown>
|
||||
args: Array<unknown>,
|
||||
name: string
|
||||
): Promise<RedisCommandReply<F>> {
|
||||
const { args: redisArgs, options } = transformCommandArguments(fn, args);
|
||||
return transformCommandReply(
|
||||
fn,
|
||||
await this.executeFunction(fn, redisArgs, options),
|
||||
await this.executeFunction(name, fn, redisArgs, options),
|
||||
redisArgs.preserve
|
||||
);
|
||||
}
|
||||
|
||||
executeFunction(
|
||||
name: string,
|
||||
fn: RedisFunction,
|
||||
args: RedisCommandArguments,
|
||||
options?: ClientCommandOptions
|
||||
): Promise<RedisCommandRawReply> {
|
||||
return this.#sendCommand(
|
||||
fCallArguments(fn, args),
|
||||
fCallArguments(name, fn, args),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
@@ -141,8 +141,8 @@ export default class RedisClientMultiCommand {
|
||||
return this;
|
||||
}
|
||||
|
||||
functionsExecutor(fn: RedisFunction, args: Array<unknown>): this {
|
||||
this.#multi.addFunction(fn, args);
|
||||
functionsExecutor(fn: RedisFunction, args: Array<unknown>, name: string): this {
|
||||
this.#multi.addFunction(name, fn, args);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -124,12 +124,14 @@ export default class RedisCluster<
|
||||
|
||||
async functionsExecutor<F extends RedisFunction>(
|
||||
fn: F,
|
||||
args: Array<unknown>
|
||||
args: Array<unknown>,
|
||||
name: string,
|
||||
): Promise<RedisCommandReply<F>> {
|
||||
const { args: redisArgs, options } = transformCommandArguments(fn, args);
|
||||
return transformCommandReply(
|
||||
fn,
|
||||
await this.executeFunction(
|
||||
name,
|
||||
fn,
|
||||
args,
|
||||
redisArgs,
|
||||
@@ -140,6 +142,7 @@ export default class RedisCluster<
|
||||
}
|
||||
|
||||
async executeFunction(
|
||||
name: string,
|
||||
fn: RedisFunction,
|
||||
originalArgs: Array<unknown>,
|
||||
redisArgs: RedisCommandArguments,
|
||||
@@ -148,7 +151,7 @@ export default class RedisCluster<
|
||||
return this.#execute(
|
||||
RedisCluster.extractFirstKey(fn, originalArgs, redisArgs),
|
||||
fn.IS_READ_ONLY,
|
||||
client => client.executeFunction(fn, redisArgs, options)
|
||||
client => client.executeFunction(name, fn, redisArgs, options)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -103,8 +103,8 @@ export default class RedisClusterMultiCommand {
|
||||
return this;
|
||||
}
|
||||
|
||||
functionsExecutor(fn: RedisFunction, args: Array<unknown>): this {
|
||||
const transformedArguments = this.#multi.addFunction(fn, args);
|
||||
functionsExecutor(fn: RedisFunction, args: Array<unknown>, name: string): this {
|
||||
const transformedArguments = this.#multi.addFunction(name, fn, args);
|
||||
this.#firstKey ??= RedisCluster.extractFirstKey(fn, args, transformedArguments);
|
||||
return this;
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
|
||||
import { CommandOptions, isCommandOptions } from './command-options';
|
||||
import { RedisCommand, RedisCommandArguments, RedisCommandReply, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts } from './commands';
|
||||
import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandReply, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts } from './commands';
|
||||
|
||||
type Instantiable<T = any> = new (...args: Array<any>) => T;
|
||||
|
||||
type CommandsExecutor<C extends RedisCommand = RedisCommand> =
|
||||
(command: C, args: Array<unknown>) => unknown;
|
||||
(command: C, args: Array<unknown>, name: string) => unknown;
|
||||
|
||||
interface AttachCommandsConfig<C extends RedisCommand> {
|
||||
BaseClass: Instantiable;
|
||||
@@ -20,7 +20,7 @@ export function attachCommands<C extends RedisCommand>({
|
||||
}: AttachCommandsConfig<C>): void {
|
||||
for (const [name, command] of Object.entries(commands)) {
|
||||
BaseClass.prototype[name] = function (...args: Array<unknown>): unknown {
|
||||
return executor.call(this, command, args);
|
||||
return executor.call(this, command, args, name);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ function attachWithNamespaces<C extends RedisCommand>({
|
||||
Commander.prototype[namespace] = {};
|
||||
for (const [name, command] of Object.entries(commands)) {
|
||||
Commander.prototype[namespace][name] = function (...args: Array<unknown>): unknown {
|
||||
return executor.call(this.self, command, args);
|
||||
return executor.call(this.self, command, args, name);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -138,10 +138,14 @@ export function transformCommandReply<C extends RedisCommand>(
|
||||
return command.transformReply(rawReply, preserved);
|
||||
}
|
||||
|
||||
export function fCallArguments(fn: RedisFunction, args: RedisCommandArguments): RedisCommandArguments {
|
||||
export function fCallArguments(
|
||||
name: RedisCommandArgument,
|
||||
fn: RedisFunction,
|
||||
args: RedisCommandArguments
|
||||
): RedisCommandArguments {
|
||||
const actualArgs: RedisCommandArguments = [
|
||||
fn.IS_READ_ONLY ? 'FCALL_RO' : 'FCALL',
|
||||
fn.NAME
|
||||
name
|
||||
];
|
||||
|
||||
if (fn.NUMBER_OF_KEYS !== undefined) {
|
||||
|
@@ -60,7 +60,6 @@ export interface RedisModules {
|
||||
}
|
||||
|
||||
export interface RedisFunction extends RedisCommand {
|
||||
NAME: string;
|
||||
NUMBER_OF_KEYS?: number;
|
||||
}
|
||||
|
||||
|
@@ -23,8 +23,9 @@ export default class RedisMultiCommand {
|
||||
});
|
||||
}
|
||||
|
||||
addFunction(fn: RedisFunction, args: Array<unknown>): RedisCommandArguments {
|
||||
addFunction(name: string, fn: RedisFunction, args: Array<unknown>): RedisCommandArguments {
|
||||
const transformedArguments = fCallArguments(
|
||||
name,
|
||||
fn,
|
||||
fn.transformArguments(...args)
|
||||
);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import TestUtils from '@node-redis/test-utils';
|
||||
import TestUtils from '@redis/test-utils';
|
||||
import { SinonSpy } from 'sinon';
|
||||
import { promiseTimeout } from './utils';
|
||||
|
||||
|
Reference in New Issue
Block a user