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.Redisinstancekey_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.Redisinstancekey_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 subscribe(channels: Iterable[str]) None[原始碼]¶
Subscribe to
channels, and enable publishing to them
- async publish(data: bytes, channels: Iterable[str]) None[原始碼]¶
Publish
datatochannels備註
This operation is performed atomically, using a lua script
- 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
MAXLENto the streamsredis¶ -- A
redis.asyncio.Redisinstancekey_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 existcap_streams_approximate¶ -- Set the streams
MAXLENusing the~approximation operator for improved performancestream_ttl¶ -- TTL of a stream in milliseconds or as a timedelta. A streams TTL will be set on each publishing operation using
PEXPIRE
- async publish(data: bytes, channels: Iterable[str]) None[原始碼]¶
Publish
datatochannels.備註
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 forstream_sleep_no_subscriptionsmilliseconds.