11import * as LinkedList from 'yallist' ;
22import { AbortError } from '../errors' ;
33import { RedisCommandArguments , RedisCommandRawReply } from '../commands' ;
4+
45// We need to use 'require', because it's not possible with Typescript to import
56// classes that are exported as 'module.exports = class`, without esModuleInterop
67// set to true.
78const RedisParser = require ( 'redis-parser' ) ;
9+
810export interface QueueCommandOptions {
911 asap ?: boolean ;
1012 chainId ?: symbol ;
1113 signal ?: AbortSignal ;
14+ ignorePubSubMode ?: boolean ;
1215}
16+
1317interface CommandWaitingToBeSent extends CommandWaitingForReply {
1418 args : RedisCommandArguments ;
1519 chainId ?: symbol ;
@@ -18,16 +22,19 @@ interface CommandWaitingToBeSent extends CommandWaitingForReply {
1822 listener ( ) : void ;
1923 } ;
2024}
25+
2126interface CommandWaitingForReply {
2227 resolve ( reply ?: unknown ) : void ;
2328 reject ( err : Error ) : void ;
2429 channelsCounter ?: number ;
2530 bufferMode ?: boolean ;
2631}
32+
2733export enum PubSubSubscribeCommands {
2834 SUBSCRIBE = 'SUBSCRIBE' ,
2935 PSUBSCRIBE = 'PSUBSCRIBE'
3036}
37+
3138export enum PubSubUnsubscribeCommands {
3239 UNSUBSCRIBE = 'UNSUBSCRIBE' ,
3340 PUNSUBSCRIBE = 'PUNSUBSCRIBE'
@@ -135,7 +142,7 @@ export default class RedisCommandsQueue {
135142 }
136143
137144 addCommand < T = RedisCommandRawReply > ( args : RedisCommandArguments , options ?: QueueCommandOptions , bufferMode ?: boolean ) : Promise < T > {
138- if ( this . #pubSubState) {
145+ if ( this . #pubSubState && ! options ?. ignorePubSubMode ) {
139146 return Promise . reject ( new Error ( 'Cannot send commands in PubSub mode' ) ) ;
140147 } else if ( this . #maxLength && this . #waitingToBeSent. length + this . #waitingForReply. length >= this . #maxLength) {
141148 return Promise . reject ( new Error ( 'The queue is full' ) ) ;
0 commit comments