How to use the aioredis.Channel function in aioredis

To help you get started, we’ve selected a few aioredis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MrNaif2018 / bitcart / tests / test_utils.py View on Github external
async def test_make_subscriber():
    sub, chan = await utils.make_subscriber("test")
    assert sub is not None
    assert chan is not None
    assert isinstance(sub, aioredis.Redis)
    assert isinstance(chan, aioredis.Channel)
    await sub.subscribe("channel:test")
    settings.loop.create_task(reader(chan))
    assert await utils.publish_message("test", {"hello": "world"}) == 1
github Home-Automation-Hub / Home-Automation-Hub / src / home_automation_hub / websocket.py View on Github external
async def redis_pubsub_handler():
    redis = await aioredis.create_connection(address=redis_connection_host,
    db=redis_connection_db)
    channel = aioredis.Channel("websocket", is_pattern=False)
    redis.execute_pubsub("subscribe", channel)

    while True:
        message = await channel.get()
        if message:
            for queue in socket_queues.values():
                queue.put_nowait(message.decode("UTF-8"))
github aio-libs / aioredis / examples / pubsub2.py View on Github external
async def pubsub():
    sub = await aioredis.create_redis(
         'redis://localhost')

    ch1, ch2 = await sub.subscribe('channel:1', 'channel:2')
    assert isinstance(ch1, aioredis.Channel)
    assert isinstance(ch2, aioredis.Channel)

    async def async_reader(channel):
        while await channel.wait_message():
            msg = await channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

    tsk1 = asyncio.ensure_future(async_reader(ch1))

    # Or alternatively:

    async def async_reader2(channel):
        while True:
            msg = await channel.get(encoding='utf-8')
            if msg is None:
github aio-libs / aioredis / examples / py34 / pubsub2.py View on Github external
@asyncio.coroutine
def pubsub():
    sub = yield from aioredis.create_redis(
         ('localhost', 6379))

    ch1, ch2 = yield from sub.subscribe('channel:1', 'channel:2')
    assert isinstance(ch1, aioredis.Channel)
    assert isinstance(ch2, aioredis.Channel)

    @asyncio.coroutine
    def async_reader(channel):
        while (yield from channel.wait_message()):
            msg = yield from channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

    tsk1 = asyncio.async(async_reader(ch1))

    # Or alternatively:

    @asyncio.coroutine
    def async_reader2(channel):
        while True:
            msg = yield from channel.get(encoding='utf-8')
github aio-libs / aioredis / examples / py34 / pubsub2.py View on Github external
@asyncio.coroutine
def pubsub():
    sub = yield from aioredis.create_redis(
         ('localhost', 6379))

    ch1, ch2 = yield from sub.subscribe('channel:1', 'channel:2')
    assert isinstance(ch1, aioredis.Channel)
    assert isinstance(ch2, aioredis.Channel)

    @asyncio.coroutine
    def async_reader(channel):
        while (yield from channel.wait_message()):
            msg = yield from channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

    tsk1 = asyncio.async(async_reader(ch1))

    # Or alternatively:

    @asyncio.coroutine
    def async_reader2(channel):
        while True:
github aio-libs / aioredis / examples / pubsub2.py View on Github external
async def pubsub():
    sub = await aioredis.create_redis(
         'redis://localhost')

    ch1, ch2 = await sub.subscribe('channel:1', 'channel:2')
    assert isinstance(ch1, aioredis.Channel)
    assert isinstance(ch2, aioredis.Channel)

    async def async_reader(channel):
        while await channel.wait_message():
            msg = await channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

    tsk1 = asyncio.ensure_future(async_reader(ch1))

    # Or alternatively:

    async def async_reader2(channel):
        while True:
            msg = await channel.get(encoding='utf-8')
            if msg is None:
                break