| 208 | } |
| 209 | |
| 210 | private handleMonitorReply(reply: ReplyData): boolean { |
| 211 | if (this.redis.status !== "monitoring") { |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | const replyStr = reply.toString(); |
| 216 | if (replyStr === "OK") { |
| 217 | // Valid commands in the monitoring mode are AUTH and MONITOR, |
| 218 | // both of which always reply with 'OK'. |
| 219 | // So if we got an 'OK', we can make certain that |
| 220 | // the reply is made to AUTH & MONITOR. |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | // Since commands sent in the monitoring mode will trigger an exception, |
| 225 | // any replies we received in the monitoring mode should consider to be |
| 226 | // realtime monitor data instead of result of commands. |
| 227 | const len = replyStr.indexOf(" "); |
| 228 | const timestamp = replyStr.slice(0, len); |
| 229 | const argIndex = replyStr.indexOf('"'); |
| 230 | const args = replyStr |
| 231 | .slice(argIndex + 1, -1) |
| 232 | .split('" "') |
| 233 | .map((elem) => elem.replace(/\\"/g, '"')); |
| 234 | const dbAndSource = replyStr.slice(len + 2, argIndex - 2).split(" "); |
| 235 | this.redis.emit("monitor", timestamp, args, dbAndSource[1], dbAndSource[0]); |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | private shiftCommand(reply: ReplyData | Error): CommandItem | null { |
| 240 | const item = this.redis.commandQueue.shift(); |