Is there a way to asynchronously wait for a key in redis?

Viewed 619

Is it possible to asynchronously wait until some key exists in redis?

My current idea below

import asyncio


red = connect_to_redis()

def get_value(key)
    res = None
    for _ in range(100):
        if red.exists(key):
            res = red.get(key)
            break
        await asyncio.sleep(0.1)
    return res

Is there a better solution to this?

0 Answers
Related