redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.06k stars 108 forks source link

Thread/Coroutine Safety of Redis Connection #552

Open bearrito opened 11 months ago

bearrito commented 11 months ago

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