@@ -19,6 +19,13 @@ export interface SendCommandOptions {
1919 * @default false
2020 */
2121 returnUint8Arrays ?: boolean ;
22+
23+ /**
24+ * When this option is set, the command is executed directly without queueing.
25+ *
26+ * @default false
27+ */
28+ inline ?: boolean ;
2229}
2330
2431export interface Connection {
@@ -126,8 +133,8 @@ export class RedisConnection implements Connection {
126133 ) : Promise < void > {
127134 try {
128135 password && username
129- ? await this . sendCommand ( "AUTH" , [ username , password ] )
130- : await this . sendCommand ( "AUTH" , [ password ] ) ;
136+ ? await this . sendCommand ( "AUTH" , [ username , password ] , { inline : true } )
137+ : await this . sendCommand ( "AUTH" , [ password ] , { inline : true } ) ;
131138 } catch ( error ) {
132139 if ( error instanceof ErrorReplyError ) {
133140 throw new AuthenticationError ( "Authentication failed" , {
@@ -143,7 +150,7 @@ export class RedisConnection implements Connection {
143150 db : number | undefined = this . options . db ,
144151 ) : Promise < void > {
145152 if ( ! db ) throw new Error ( "The database index is undefined." ) ;
146- await this . sendCommand ( "SELECT" , [ db ] ) ;
153+ await this . sendCommand ( "SELECT" , [ db ] , { inline : true } ) ;
147154 }
148155
149156 private enqueueCommand (
@@ -160,13 +167,16 @@ export class RedisConnection implements Connection {
160167 args ?: Array < RedisValue > ,
161168 options ?: SendCommandOptions ,
162169 ) : Promise < RedisReply > {
163- const { promise, resolve, reject } = Promise . withResolvers < RedisReply > ( ) ;
164170 const execute = ( ) =>
165171 this . #protocol. sendCommand (
166172 command ,
167173 args ?? kEmptyRedisArgs ,
168174 options ?. returnUint8Arrays ,
169175 ) ;
176+ if ( options ?. inline ) {
177+ return execute ( ) ;
178+ }
179+ const { promise, resolve, reject } = Promise . withResolvers < RedisReply > ( ) ;
170180 this . enqueueCommand ( { execute, resolve, reject } ) ;
171181
172182 return promise ;
0 commit comments