aio pubsub
Project description
aio_pubsub ########
- 安装 ==========
.. code-block:: shell
pip install aiopubsub-py3 pip install aiopubsub-py3[redis] pip install aiopubsub-py3[redis2]
- 示例 ==========
- 2.1 发布
.. code-block:: python
from aiopubsub import Pubsub
async def main():
pubpub = Pubsub(Pubsub.REDIS, port=16379)
count = await pubpub.publish("foo", {"test": 1})
print(count)
async with pubpub.get_pub(namespace="cs") as pub:
count = await pub.publish("foo", {"test": 2})
print(count)
count = await pub.publish("foo", {"test": 3})
print(count)
await pubpub.close()
- 2.2 订阅
.. code-block:: python
from aiopubsub import Pubsub
async def main():
pubsub = Pubsub(Pubsub.REDIS, port=16379)
async with pubsub.get_sub(namespace="cs") as sub:
await sub.subscribe("foo")
async for k in sub.listen():
print(k)
await pubsub.close()
- 2.3 模糊订阅
.. code-block:: python
from aiopubsub import Pubsub
async def main():
pubsub = Pubsub(Pubsub.REDIS, port=16379)
async with pubsub.get_sub(namespace="cs") as psub:
await psub.psubscribe("foo*")
async for k in psub.listen():
print(k)
await pubsub.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiopubsub-py3-1.0.3.tar.gz
(7.5 kB
view hashes)
Built Distribution
Close
Hashes for aiopubsub_py3-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3098eb7fa675c8e660b867bb63c3fbb38446f43f0cc8dfdbb8c17ede9dc3fe07 |
|
MD5 | 125d38274b68dae53c57e9a1dbcd13c6 |
|
BLAKE2b-256 | 229065673fcecef45177b06b8de6feb7c079630e7c04f47b18e587a340186d56 |