diff --git a/connection.ts b/connection.ts index 615a91a3..eaf44623 100644 --- a/connection.ts +++ b/connection.ts @@ -19,6 +19,13 @@ export interface SendCommandOptions { * @default false */ returnUint8Arrays?: boolean; + + /** + * When this option is set, the command is executed directly without queueing. + * + * @default false + */ + inline?: boolean; } export interface Connection { @@ -126,8 +133,8 @@ export class RedisConnection implements Connection { ): Promise { try { password && username - ? await this.sendCommand("AUTH", [username, password]) - : await this.sendCommand("AUTH", [password]); + ? await this.sendCommand("AUTH", [username, password], { inline: true }) + : await this.sendCommand("AUTH", [password], { inline: true }); } catch (error) { if (error instanceof ErrorReplyError) { throw new AuthenticationError("Authentication failed", { @@ -143,7 +150,7 @@ export class RedisConnection implements Connection { db: number | undefined = this.options.db, ): Promise { if (!db) throw new Error("The database index is undefined."); - await this.sendCommand("SELECT", [db]); + await this.sendCommand("SELECT", [db], { inline: true }); } private enqueueCommand( @@ -160,13 +167,16 @@ export class RedisConnection implements Connection { args?: Array, options?: SendCommandOptions, ): Promise { - const { promise, resolve, reject } = Promise.withResolvers(); const execute = () => this.#protocol.sendCommand( command, args ?? kEmptyRedisArgs, options?.returnUint8Arrays, ); + if (options?.inline) { + return execute(); + } + const { promise, resolve, reject } = Promise.withResolvers(); this.enqueueCommand({ execute, resolve, reject }); return promise;