You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-11 22:42:42 +03:00
replace "modern" with "v4"
This commit is contained in:
@@ -4,7 +4,7 @@ const cronometro = require('cronometro'),
|
||||
|
||||
let client;
|
||||
cronometro({
|
||||
'New Client - Modern Mode': {
|
||||
'New Client': {
|
||||
async before() {
|
||||
client = newRedis.createClient();
|
||||
await client.connect();
|
||||
|
@@ -41,7 +41,7 @@ describe('Client', () => {
|
||||
});
|
||||
|
||||
before(() => client.connect());
|
||||
afterEach(() => client.modern.flushAll());
|
||||
afterEach(() => client.v4.flushAll());
|
||||
after(() => client.disconnect());
|
||||
|
||||
it('client.sendCommand should call the callback', done => {
|
||||
@@ -61,12 +61,12 @@ describe('Client', () => {
|
||||
|
||||
it('client.sendCommand should work without callback', async () => {
|
||||
(client as any).sendCommand('PING');
|
||||
await client.modern.ping(); // make sure the first command was replied
|
||||
await client.v4.ping(); // make sure the first command was replied
|
||||
});
|
||||
|
||||
it('client.modern.sendCommand should return a promise', async () => {
|
||||
it('client.v4.sendCommand should return a promise', async () => {
|
||||
assert.equal(
|
||||
await client.modern.sendCommand(['PING']),
|
||||
await client.v4.sendCommand(['PING']),
|
||||
'PONG'
|
||||
);
|
||||
});
|
||||
@@ -137,12 +137,12 @@ describe('Client', () => {
|
||||
(client as any).multi()
|
||||
.ping()
|
||||
.exec();
|
||||
await client.modern.ping(); // make sure the first command was replied
|
||||
await client.v4.ping(); // make sure the first command was replied
|
||||
});
|
||||
|
||||
it('client.modern.exec should return a promise', async () => {
|
||||
it('client.v4.exec should return a promise', async () => {
|
||||
assert.deepEqual(
|
||||
await ((client as any).multi().modern
|
||||
await ((client as any).multi().v4
|
||||
.ping()
|
||||
.exec()),
|
||||
['PONG']
|
||||
|
@@ -68,7 +68,7 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
||||
readonly #socket: RedisSocket;
|
||||
readonly #queue: RedisCommandsQueue;
|
||||
readonly #Multi: typeof RedisMultiCommand & { new(): RedisMultiCommandType<M, S> };
|
||||
readonly #modern: Record<string, Function> = {};
|
||||
readonly #v4: Record<string, Function> = {};
|
||||
#selectedDB = 0;
|
||||
|
||||
get options(): RedisClientOptions<M> | null | undefined {
|
||||
@@ -79,12 +79,12 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
||||
return this.#socket.isOpen;
|
||||
}
|
||||
|
||||
get modern(): Record<string, Function> {
|
||||
get v4(): Record<string, Function> {
|
||||
if (!this.#options?.legacyMode) {
|
||||
throw new Error('the client is not in "legacy mode"');
|
||||
}
|
||||
|
||||
return this.#modern;
|
||||
return this.#v4;
|
||||
}
|
||||
|
||||
constructor(options?: RedisClientOptions<M, S>) {
|
||||
@@ -218,13 +218,13 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
||||
#legacyMode(): void {
|
||||
if (!this.#options?.legacyMode) return;
|
||||
|
||||
this.#modern.sendCommand = this.sendCommand.bind(this);
|
||||
this.#v4.sendCommand = this.sendCommand.bind(this);
|
||||
|
||||
(this as any).sendCommand = (...args: Array<unknown>): void => {
|
||||
const options = isCommandOptions(args[0]) && args.shift(),
|
||||
callback = typeof args[args.length - 1] === 'function' && (args.pop() as Function);
|
||||
|
||||
this.#modern.sendCommand(args.flat(), options)
|
||||
this.#v4.sendCommand(args.flat(), options)
|
||||
.then((reply: unknown) => {
|
||||
if (!callback) return;
|
||||
|
||||
@@ -274,7 +274,7 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
||||
}
|
||||
|
||||
#defineLegacyCommand(name: string): void {
|
||||
this.#modern[name] = (this as any)[name];
|
||||
this.#v4[name] = (this as any)[name];
|
||||
(this as any)[name] = function (...args: Array<unknown>): void {
|
||||
this.sendCommand(name, ...args);
|
||||
};
|
||||
|
@@ -48,14 +48,14 @@ export default class RedisMultiCommand<M extends RedisModules = RedisModules, S
|
||||
|
||||
readonly #scriptsInUse = new Set<string>();
|
||||
|
||||
readonly #modern: Record<string, Function> = {};
|
||||
readonly #v4: Record<string, Function> = {};
|
||||
|
||||
get modern(): Record<string, Function> {
|
||||
get v4(): Record<string, Function> {
|
||||
if (!this.#clientOptions?.legacyMode) {
|
||||
throw new Error('client is not in "legacy mode"');
|
||||
}
|
||||
|
||||
return this.#modern;
|
||||
return this.#v4;
|
||||
}
|
||||
|
||||
constructor(executor: RedisMultiExecutor, clientOptions?: RedisClientOptions<M, S>) {
|
||||
@@ -110,12 +110,12 @@ export default class RedisMultiCommand<M extends RedisModules = RedisModules, S
|
||||
#legacyMode(): Record<string, Function> | undefined {
|
||||
if (!this.#clientOptions?.legacyMode) return;
|
||||
|
||||
this.#modern.exec = this.exec.bind(this);
|
||||
this.#modern.addCommand = this.addCommand.bind(this);
|
||||
this.#v4.exec = this.exec.bind(this);
|
||||
this.#v4.addCommand = this.addCommand.bind(this);
|
||||
|
||||
(this as any).exec = function (...args: Array<unknown>): void {
|
||||
const callback = typeof args[args.length - 1] === 'function' && args.pop() as Function;
|
||||
this.#modern.exec()
|
||||
this.#v4.exec()
|
||||
.then((reply: unknown) => {
|
||||
if (!callback) return;
|
||||
|
||||
@@ -152,7 +152,7 @@ export default class RedisMultiCommand<M extends RedisModules = RedisModules, S
|
||||
}
|
||||
|
||||
#defineLegacyCommand(name: string): void {
|
||||
this.#modern[name] = (this as any)[name];
|
||||
this.#v4[name] = (this as any)[name];
|
||||
|
||||
// TODO: https://github.com/NodeRedis/node-redis#commands:~:text=minimal%20parsing
|
||||
(this as any)[name] = function (...args: Array<unknown>) {
|
||||
|
Reference in New Issue
Block a user