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