redis

class litestar.channels.backends.redis.RedisChannelsBackend[原始碼]

基底類別:ChannelsBackend, ABC

__init__(*, redis: Redis, key_prefix: str, stream_sleep_no_subscriptions: int) None[原始碼]

Base redis channels backend.

參數:
  • redis -- A redis.asyncio.Redis instance

  • key_prefix -- Key prefix to use for storing data in redis

  • stream_sleep_no_subscriptions -- Amount of time in milliseconds to pause the stream_events() generator, should no subscribers exist

class litestar.channels.backends.redis.RedisChannelsPubSubBackend[原始碼]

基底類別:RedisChannelsBackend

__init__(*, redis: Redis, stream_sleep_no_subscriptions: int = 1, key_prefix: str = 'LITESTAR_CHANNELS') None[原始碼]

Redis channels backend, Pub/Sub.

This backend provides low overhead and resource usage but no support for history.

參數:
  • redis -- A redis.asyncio.Redis instance

  • key_prefix -- Key prefix to use for storing data in redis

  • stream_sleep_no_subscriptions -- Amount of time in milliseconds to pause the stream_events() generator, should no subscribers exist

async on_startup() None[原始碼]

Called by the plugin on application startup

async on_shutdown() None[原始碼]

Called by the plugin on application shutdown

async subscribe(channels: Iterable[str]) None[原始碼]

Subscribe to channels, and enable publishing to them

async unsubscribe(channels: Iterable[str]) None[原始碼]

Stop listening for events on channels

async publish(data: bytes, channels: Iterable[str]) None[原始碼]

Publish data to channels

備註

This operation is performed atomically, using a lua script

async stream_events() AsyncGenerator[tuple[str, Any], None][原始碼]

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

If no channels have been subscribed to yet via subscribe(), sleep for stream_sleep_no_subscriptions milliseconds.

async get_history(channel: str, limit: int | None = None) list[bytes][原始碼]

Not implemented

class litestar.channels.backends.redis.RedisChannelsStreamBackend[原始碼]

基底類別:RedisChannelsBackend

__init__(history: int, *, redis: Redis, stream_sleep_no_subscriptions: int = 1, cap_streams_approximate: bool = True, stream_ttl: int | timedelta = datetime.timedelta(seconds=60), key_prefix: str = 'LITESTAR_CHANNELS') None[原始碼]

Redis channels backend, streams.

參數:
  • history -- Amount of messages to keep. This will set a MAXLEN to the streams

  • redis -- A redis.asyncio.Redis instance

  • key_prefix -- Key prefix to use for streams

  • stream_sleep_no_subscriptions -- Amount of time in milliseconds to pause the stream_events() generator, should no subscribers exist

  • cap_streams_approximate -- Set the streams MAXLEN using the ~ approximation operator for improved performance

  • stream_ttl -- TTL of a stream in milliseconds or as a timedelta. A streams TTL will be set on each publishing operation using PEXPIRE

async on_startup() None[原始碼]

Called on application startup

async on_shutdown() None[原始碼]

Called on application shutdown

async subscribe(channels: Iterable[str]) None[原始碼]

Subscribe to channels

async unsubscribe(channels: Iterable[str]) None[原始碼]

Unsubscribe from channels

async publish(data: bytes, channels: Iterable[str]) None[原始碼]

Publish data to channels.

備註

This operation is performed atomically, using a Lua script

async stream_events() AsyncGenerator[tuple[str, Any], None][原始碼]

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

If no channels have been subscribed to yet via subscribe(), sleep for stream_sleep_no_subscriptions milliseconds.

async get_history(channel: str, limit: int | None = None) list[bytes][原始碼]

Return the history of channels, returning at most limit messages

async flush_all() int[原始碼]

Delete all stream keys with the key_prefix.

重要

This method is incompatible with redis clusters