MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pubsubSubscribePattern

Function pubsubSubscribePattern

app/redis-6.2.6/src/pubsub.c:194–217  ·  view source on GitHub ↗

Subscribe a client to a pattern. Returns 1 if the operation succeeded, or 0 if the client was already subscribed to that pattern. */

Source from the content-addressed store, hash-verified

192
193/* Subscribe a client to a pattern. Returns 1 if the operation succeeded, or 0 if the client was already subscribed to that pattern. */
194int pubsubSubscribePattern(client *c, robj *pattern) {
195 dictEntry *de;
196 list *clients;
197 int retval = 0;
198
199 if (listSearchKey(c->pubsub_patterns,pattern) == NULL) {
200 retval = 1;
201 listAddNodeTail(c->pubsub_patterns,pattern);
202 incrRefCount(pattern);
203 /* Add the client to the pattern -> list of clients hash table */
204 de = dictFind(server.pubsub_patterns,pattern);
205 if (de == NULL) {
206 clients = listCreate();
207 dictAdd(server.pubsub_patterns,pattern,clients);
208 incrRefCount(pattern);
209 } else {
210 clients = dictGetVal(de);
211 }
212 listAddNodeTail(clients,c);
213 }
214 /* Notify the client */
215 addReplyPubsubPatSubscribed(c,pattern);
216 return retval;
217}
218
219/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
220 * 0 if the client was not subscribed to the specified channel. */

Callers 1

psubscribeCommandFunction · 0.85

Calls 7

listSearchKeyFunction · 0.85
listAddNodeTailFunction · 0.85
incrRefCountFunction · 0.85
listCreateFunction · 0.85
dictFindFunction · 0.70
dictAddFunction · 0.70

Tested by

no test coverage detected