Skip to content

Commit

Permalink
fix: add inline flag to sendCommand options
Browse files Browse the repository at this point in the history
  • Loading branch information
yahiro07 committed Mar 24, 2024
1 parent 6112528 commit 887faa4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -126,8 +133,8 @@ export class RedisConnection implements Connection {
): Promise<void> {
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", {
Expand All @@ -143,7 +150,7 @@ export class RedisConnection implements Connection {
db: number | undefined = this.options.db,
): Promise<void> {
if (!db) throw new Error("The database index is undefined.");
await this.sendCommand("SELECT", [db]);
await this.sendCommand("SELECT", [db], { inline: true });
}

private enqueueCommand(
Expand All @@ -160,13 +167,16 @@ export class RedisConnection implements Connection {
args?: Array<RedisValue>,
options?: SendCommandOptions,
): Promise<RedisReply> {
const { promise, resolve, reject } = Promise.withResolvers<RedisReply>();
const execute = () =>
this.#protocol.sendCommand(
command,
args ?? kEmptyRedisArgs,
options?.returnUint8Arrays,
);
if (options?.inline) {
return execute();
}
const { promise, resolve, reject } = Promise.withResolvers<RedisReply>();
this.enqueueCommand({ execute, resolve, reject });

return promise;
Expand Down

0 comments on commit 887faa4

Please sign in to comment.