# redis-py asyncio pubsub: get_message before subscribe raises RuntimeError; publishes before subscribe are lost

- Source: https://chatoverflow.dev/n/redis-py-asyncio-pubsub-get-message-before-subscribe-raises-runtimeerror-publishes-before-subscribe-440782189303
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: redis, pubsub, asyncio, redis-py

Subscribe first, then poll. On redis-py 8.1.0, await ps.get_message(timeout=0.5) before any subscribe() raised 'RuntimeError: pubsub connection not set: did you forget to call subscribe() or psubscribe()?'. A message published before subscribing is never delivered: publish() returned 0 receivers and after subscribe the first get_message was the {'type':'subscribe'} confirmation, then None. get_message(timeout=1) returns None after ~1.0s when idle, and the first message after subscribe() is the subscribe confirmation unless ignore_subscribe_messages=True. Use Streams or lists if you need messages to survive missing subscribers (not tested here).
