1
1
import * as LinkedList from 'yallist' ;
2
2
import { AbortError } from '../errors' ;
3
3
import { RedisCommandArguments , RedisCommandRawReply } from '../commands' ;
4
+
4
5
// We need to use 'require', because it's not possible with Typescript to import
5
6
// classes that are exported as 'module.exports = class`, without esModuleInterop
6
7
// set to true.
7
8
const RedisParser = require ( 'redis-parser' ) ;
9
+
8
10
export interface QueueCommandOptions {
9
11
asap ?: boolean ;
10
12
chainId ?: symbol ;
11
13
signal ?: AbortSignal ;
14
+ ignorePubSubMode ?: boolean ;
12
15
}
16
+
13
17
interface CommandWaitingToBeSent extends CommandWaitingForReply {
14
18
args : RedisCommandArguments ;
15
19
chainId ?: symbol ;
@@ -18,16 +22,19 @@ interface CommandWaitingToBeSent extends CommandWaitingForReply {
18
22
listener ( ) : void ;
19
23
} ;
20
24
}
25
+
21
26
interface CommandWaitingForReply {
22
27
resolve ( reply ?: unknown ) : void ;
23
28
reject ( err : Error ) : void ;
24
29
channelsCounter ?: number ;
25
30
bufferMode ?: boolean ;
26
31
}
32
+
27
33
export enum PubSubSubscribeCommands {
28
34
SUBSCRIBE = 'SUBSCRIBE' ,
29
35
PSUBSCRIBE = 'PSUBSCRIBE'
30
36
}
37
+
31
38
export enum PubSubUnsubscribeCommands {
32
39
UNSUBSCRIBE = 'UNSUBSCRIBE' ,
33
40
PUNSUBSCRIBE = 'PUNSUBSCRIBE'
@@ -135,7 +142,7 @@ export default class RedisCommandsQueue {
135
142
}
136
143
137
144
addCommand < T = RedisCommandRawReply > ( args : RedisCommandArguments , options ?: QueueCommandOptions , bufferMode ?: boolean ) : Promise < T > {
138
- if ( this . #pubSubState) {
145
+ if ( this . #pubSubState && ! options ?. ignorePubSubMode ) {
139
146
return Promise . reject ( new Error ( 'Cannot send commands in PubSub mode' ) ) ;
140
147
} else if ( this . #maxLength && this . #waitingToBeSent. length + this . #waitingForReply. length >= this . #maxLength) {
141
148
return Promise . reject ( new Error ( 'The queue is full' ) ) ;
0 commit comments