memory

class litestar.channels.backends.memory.MemoryChannelsBackend[源代码]

基类:ChannelsBackend

An in-memory channels backend

__init__(history: int = 0) None[源代码]
async on_startup() None[源代码]

Called by the plugin on application startup

async on_shutdown() None[源代码]

Called by the plugin on application shutdown

async publish(data: bytes, channels: Iterable[str]) None[源代码]

Publish data to channels. If a channel has not yet been subscribed to, this will be a no-op.

参数:
  • data -- Data to publish

  • channels -- Channels to publish to

返回:

None

抛出:

RuntimeError -- If on_startup has not been called yet

async subscribe(channels: Iterable[str]) None[源代码]

Subscribe to channels, and enable publishing to them

async unsubscribe(channels: Iterable[str]) None[源代码]

Unsubscribe from channels

async stream_events() AsyncGenerator[tuple[str, Any], None][源代码]

Return a generator, iterating over events of subscribed channels as they become available

async get_history(channel: str, limit: int | None = None) list[bytes][源代码]

Return the event history of channel, at most limit entries