Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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"))
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:
@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')
@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:
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