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.5.tar.gz
(7.6 kB
view hashes)
Built Distribution
Close
Hashes for aiopubsub_py3-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d451e8d6eb2f831e064caf1e40f657c85c6da7dfe30c09fd12b02a0e835bdf |
|
MD5 | 224afe73ec256bed01ac9c89a23a4ac6 |
|
BLAKE2b-256 | 7c535c5f916685451336b6742f0fe49e81875b1ffab92344a88e1fa65e4e8247 |