MCPcopy
hub / github.com/redis/ioredis / handleSubscriberReply

Method handleSubscriberReply

lib/DataHandler.ts:122–208  ·  view source on GitHub ↗
(reply: ReplyData)

Source from the content-addressed store, hash-verified

120 }
121
122 private handleSubscriberReply(reply: ReplyData): boolean {
123 if (!this.redis.condition.subscriber) {
124 return false;
125 }
126 const replyType = Array.isArray(reply) ? reply[0].toString() : null;
127 debug('receive reply "%s" in subscriber mode', replyType);
128
129 switch (replyType) {
130 case "message":
131 if (this.redis.listeners("message").length > 0) {
132 // Check if there're listeners to avoid unnecessary `toString()`.
133 this.redis.emit(
134 "message",
135 reply[1].toString(),
136 reply[2] ? reply[2].toString() : ""
137 );
138 }
139 this.redis.emit("messageBuffer", reply[1], reply[2]);
140 break;
141 case "pmessage": {
142 const pattern = reply[1].toString();
143 if (this.redis.listeners("pmessage").length > 0) {
144 this.redis.emit(
145 "pmessage",
146 pattern,
147 reply[2].toString(),
148 reply[3].toString()
149 );
150 }
151 this.redis.emit("pmessageBuffer", pattern, reply[2], reply[3]);
152 break;
153 }
154 case "smessage": {
155 if (this.redis.listeners("smessage").length > 0) {
156 this.redis.emit(
157 "smessage",
158 reply[1].toString(),
159 reply[2] ? reply[2].toString() : ""
160 );
161 }
162 this.redis.emit("smessageBuffer", reply[1], reply[2]);
163 break;
164 }
165 case "ssubscribe":
166 case "subscribe":
167 case "psubscribe": {
168 const channel = reply[1].toString();
169 this.redis.condition.subscriber.add(replyType, channel);
170 const item = this.shiftCommand(reply);
171 if (!item) {
172 return;
173 }
174 if (!fillSubCommand(item.command, reply[2])) {
175 this.redis.commandQueue.unshift(item);
176 }
177 break;
178 }
179 case "sunsubscribe":

Callers 1

returnReplyMethod · 0.95

Calls 7

shiftCommandMethod · 0.95
fillSubCommandFunction · 0.85
fillUnsubCommandFunction · 0.85
toStringMethod · 0.80
delMethod · 0.65
resolveMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected