@@ -65,9 +65,9 @@ export class MultiClient
65
65
66
66
public async multi ( ) : Promise < void > {
67
67
68
- if ( ! this . _multi && this . _queue . length ) {
68
+ if ( this . _multi ) {
69
69
70
- throw new E . E_PIPELINING ( ) ;
70
+ return ;
71
71
}
72
72
73
73
await this . _command ( 'multi' , [ ] ) ;
@@ -77,7 +77,10 @@ export class MultiClient
77
77
78
78
public async discard ( ) : Promise < void > {
79
79
80
- await this . _command ( 'discard' , [ ] ) ;
80
+ if ( this . _multi ) {
81
+
82
+ await this . _command ( 'discard' , [ ] ) ;
83
+ }
81
84
82
85
this . _queue = [ ] ;
83
86
@@ -86,8 +89,14 @@ export class MultiClient
86
89
87
90
public async exec ( ) : Promise < any > {
88
91
92
+ if ( ! this . _multi ) {
93
+
94
+ throw new E . E_NOT_MULTI_MODE ( ) ;
95
+ }
96
+
89
97
if ( ! this . _queue . length ) {
90
98
99
+ await this . discard ( ) ;
91
100
return [ ] ;
92
101
}
93
102
@@ -97,50 +106,25 @@ export class MultiClient
97
106
98
107
const ret : any [ ] = new Array ( queue . length ) ;
99
108
100
- if ( this . _multi ) {
101
-
102
- const data = await this . command ( 'EXEC' , [ ] ) ;
103
-
104
- this . _multi = false ;
105
-
106
- for ( let i = 0 ; i < queue . length ; i ++ ) {
109
+ const data = await this . command ( 'EXEC' , [ ] ) ;
107
110
108
- const qi = queue [ i ] ;
111
+ this . _multi = false ;
109
112
110
- if ( qi . process === undefined ) {
113
+ for ( let i = 0 ; i < queue . length ; i ++ ) {
111
114
112
- ret [ i ] = data [ i ] [ 1 ] ;
113
- }
114
- else if ( qi . process === null ) {
115
+ const qi = queue [ i ] ;
115
116
116
- ret [ i ] = null ;
117
- }
118
- else {
117
+ if ( qi . process === undefined ) {
119
118
120
- ret [ i ] = qi . process ( data [ i ] [ 1 ] , qi . args ) ;
121
- }
119
+ ret [ i ] = data [ i ] [ 1 ] ;
122
120
}
123
- }
124
- else {
125
-
126
- const data : any [ ] = await this . _bulkCommands ( queue ) ;
127
-
128
- for ( let i = 0 ; i < queue . length ; i ++ ) {
129
-
130
- const qi = queue [ i ] ;
131
-
132
- if ( qi . process === undefined ) {
133
-
134
- ret [ i ] = data [ i ] ;
135
- }
136
- else if ( qi . process === null ) {
121
+ else if ( qi . process === null ) {
137
122
138
- ret [ i ] = null ;
139
- }
140
- else {
123
+ ret [ i ] = null ;
124
+ }
125
+ else {
141
126
142
- ret [ i ] = qi . process ( data [ i ] , qi . args ) ;
143
- }
127
+ ret [ i ] = qi . process ( data [ i ] [ 1 ] , qi . args ) ;
144
128
}
145
129
}
146
130
@@ -183,13 +167,13 @@ export class MultiClient
183
167
'E' ,
184
168
`return function(...args) {
185
169
186
- const req = command(...args);
187
-
188
170
if (!this._multi) {
189
171
190
172
throw new E.E_NOT_MULTI_MODE();
191
173
}
192
174
175
+ const req = command(...args);
176
+
193
177
const ret = this._command(req.cmd, req.args);
194
178
195
179
this._queue.push({ args: req.args, process: process, cmd: req.cmd });
0 commit comments