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():
pub = Pubsub(Pubsub.REDIS, port=16379)
count = await pub.publish("foo1", {"test": 1})
print(count)
async with pub.get_pub() as _pub:
count = await pub.publish("foo1", {"test": 2}, _conn=_pub.conn)
print(count)
count = await pub.publish("foo1", {"test": 3}, _conn=_pub.conn)
print(count)
await pub.close()
- 2.2 订阅
.. code-block:: python
from aiopubsub import Pubsub
async def main():
sub = Pubsub(Pubsub.REDIS, port=16379)
async with sub.get_sub() as _sub:
_conn = await sub.subscribe("foo", _conn=_sub.conn)
async for k in sub.listen(_conn):
print(k)
await sub.close()
- 2.3 模糊订阅
.. code-block:: python
from aiopubsub import Pubsub
async def main():
sub = Pubsub(Pubsub.REDIS, port=16379)
async with sub.get_sub() as _sub:
_conn = await sub.psubscribe("foo*", _conn=_sub.conn)
async for k in sub.listen(_conn=_conn):
print(k)
await sub.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.1.tar.gz
(7.0 kB
view hashes)
Built Distribution
Close
Hashes for aiopubsub_py3-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb5a3900ad7da68891aba933cbf92bda72087e5ea0af755d6cab6a99317a11c0 |
|
MD5 | 97c8bdf00248d1a94d5275c8c96a7f7e |
|
BLAKE2b-256 | 8fae8d4937e89bf611aa1e9d8cf7f42419251f9481f6e0cdcb458a0545b7c3de |