Skip to main content

aio pubsub

Project description

aio_pubsub ########

  1. 安装 ==========

.. code-block:: shell

pip install aiopubsub-py3 pip install aiopubsub-py3[redis] pip install aiopubsub-py3[redis2]

  1. 示例 ==========
  • 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)

Uploaded Source

Built Distribution

aiopubsub_py3-1.0.3-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page