summaryrefslogtreecommitdiff
path: root/src/pubsub.c
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2021-02-28 13:11:18 +0100
committerGitHub <noreply@github.com>2021-02-28 14:11:18 +0200
commit6122f1c450846584eedf614551de0c97da305b45 (patch)
treec417866fb76551227649ea4be5eb02828d9c41fd /src/pubsub.c
parent4a474843fbd018cd323971b57dec976d7ad0278d (diff)
downloadredis-6122f1c450846584eedf614551de0c97da305b45.tar.gz
Shared reusable client for RM_Call() (#8516)
A single client pointer is added in the server struct. This is initialized by the first RM_Call() and reused for every subsequent RM_Call() except if it's already in use, which means that it's not used for (recursive) module calls to modules. For these, a new "fake" client is created each time. Other changes: * Avoid allocating a dict iterator in pubsubUnsubscribeAllChannels when not needed
Diffstat (limited to 'src/pubsub.c')
-rw-r--r--src/pubsub.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/pubsub.c b/src/pubsub.c
index a7b370d5d..5f7335bbe 100644
--- a/src/pubsub.c
+++ b/src/pubsub.c
@@ -250,18 +250,20 @@ int pubsubUnsubscribePattern(client *c, robj *pattern, int notify) {
/* Unsubscribe from all the channels. Return the number of channels the
* client was subscribed to. */
int pubsubUnsubscribeAllChannels(client *c, int notify) {
- dictIterator *di = dictGetSafeIterator(c->pubsub_channels);
- dictEntry *de;
int count = 0;
+ if (dictSize(c->pubsub_channels) > 0) {
+ dictIterator *di = dictGetSafeIterator(c->pubsub_channels);
+ dictEntry *de;
- while((de = dictNext(di)) != NULL) {
- robj *channel = dictGetKey(de);
+ while((de = dictNext(di)) != NULL) {
+ robj *channel = dictGetKey(de);
- count += pubsubUnsubscribeChannel(c,channel,notify);
+ count += pubsubUnsubscribeChannel(c,channel,notify);
+ }
+ dictReleaseIterator(di);
}
/* We were subscribed to nothing? Still reply to the client. */
if (notify && count == 0) addReplyPubsubUnsubscribed(c,NULL);
- dictReleaseIterator(di);
return count;
}