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

Method psubscribe

redis/asyncio/client.py:1334–1355  ·  view source on GitHub ↗

Subscribe to channel patterns. Patterns supplied as keyword arguments expect a pattern name as the key and a callable as the value. ``Subscription`` objects can also be supplied positionally with an optional handler. A pattern's callable will be invok

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

Source from the content-addressed store, hash-verified

1332 return {decode(encode(k)): v for k, v in data.items()} # type: ignore[return-value] # noqa: E501
1333
1334 async def psubscribe(
1335 self, *args: ChannelT | Subscription, **kwargs: PubSubHandler
1336 ) -> None:
1337 """
1338 Subscribe to channel patterns.
1339 Patterns supplied as keyword arguments expect a pattern name as the
1340 key and a callable as the value.
1341 ``Subscription`` objects can also be supplied positionally with an
1342 optional handler.
1343 A pattern's callable will be invoked automatically
1344 when a message is received on that pattern rather than producing a
1345 message via ``listen()``.
1346 """
1347 new_patterns = parse_pubsub_subscriptions(args, kwargs)
1348 ret_val = await self.execute_command("PSUBSCRIBE", *new_patterns.keys())
1349 # update the patterns dict AFTER we send the command. we don't want to
1350 # subscribe twice to these patterns, once for the command and again
1351 # for the reconnection.
1352 new_patterns = self._normalize_keys(new_patterns)
1353 self.patterns.update(new_patterns)
1354 self.pending_unsubscribe_patterns.difference_update(new_patterns)
1355 return ret_val
1356
1357 def punsubscribe(self, *args: ChannelT) -> Awaitable:
1358 """

Callers 3

_execute_subscribeMethod · 0.45
_execute_subscribeMethod · 0.45
refresh_subscriptionsMethod · 0.45

Calls 5

execute_commandMethod · 0.95
_normalize_keysMethod · 0.95
keysMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected