redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

Thread/Coroutine Safety of Redis Connection

Open bearrito opened this issue 2 years ago • 1 comments

Concerning https://github.com/redis/redis-om-python/blob/main/docs/connections.md#connection-objects

Module level imports and creation of redis clients might not be co-routine safe : https://github.com/redis/redis-py/issues/2835

Is it possible to augment providing a redis connection directly, and instead provide a function?

So we might end up with

def redis_provider(...) -> redis.Redis:
...


class Customer(HashModel):
    first_name: str
    last_name: str
    age: int

    class Meta:
        database_provider = redis_provider

Another use of this would be able to combine with https://github.com/testcontainers/testcontainers-python.

Test containers set a unique/random port per test invocation, so there is no way to configure a module level import

Related:

  1. https://github.com/redis/redis-om-python/issues/527
  2. https://github.com/redis/redis-om-python/issues/519

bearrito avatar Aug 08 '23 16:08 bearrito

This needs attention.

sashkent3 avatar Feb 10 '25 13:02 sashkent3