MCPcopy
hub / github.com/redis/redis-py / subscribe

Method subscribe

redis/client.py:1361–1387  ·  view source on GitHub ↗

Subscribe to channels. Channels supplied as keyword arguments expect a channel name as the key and a callable as the value. ``Subscription`` objects can also be supplied positionally with an optional handler. A channel's callable will be invoked autom

(
        self, *args: ChannelT | Subscription, **kwargs: PubSubHandler
    )

Source from the content-addressed store, hash-verified

1359 return self.execute_command("PUNSUBSCRIBE", *args)
1360
1361 def subscribe(
1362 self, *args: ChannelT | Subscription, **kwargs: PubSubHandler
1363 ) -> None:
1364 """
1365 Subscribe to channels.
1366 Channels supplied as keyword arguments expect
1367 a channel name as the key and a callable as the value.
1368 ``Subscription`` objects can also be supplied positionally with an
1369 optional handler.
1370 A channel's callable will be invoked automatically
1371 when a message is received on that channel rather than producing a
1372 message via ``listen()`` or ``get_message()``.
1373 """
1374 new_channels = parse_pubsub_subscriptions(args, kwargs)
1375 ret_val = self.execute_command("SUBSCRIBE", *new_channels.keys())
1376 # update the channels dict AFTER we send the command. we don't want to
1377 # subscribe twice to these channels, once for the command and again
1378 # for the reconnection.
1379 new_channels = self._normalize_keys(new_channels)
1380 self.channels.update(new_channels)
1381 if not self.subscribed:
1382 # Set the subscribed_event flag to True
1383 self.subscribed_event.set()
1384 # Clear the health check counter
1385 self.health_check_response_counter = 0
1386 self.pending_unsubscribe_channels.difference_update(new_channels)
1387 return ret_val
1388
1389 def unsubscribe(self, *args):
1390 """

Calls 6

execute_commandMethod · 0.95
_normalize_keysMethod · 0.95
keysMethod · 0.80
updateMethod · 0.80
setMethod · 0.45