Disable features without required Redis modules

Some features, like querying and embedded models, require
either the RediSearch or RedisJSON modules running in Redis.
Without these modules, using these features would result
in inscrutable errors.

We now disable some tests if the Redis module required for the
test is not found in the Redis instance the tests are using,
and raise errors or log messages if the same is true during
execution of HashModel and JsonModel.
This commit is contained in:
Andrew Brookins 2021-11-03 12:37:09 -07:00
parent ca48b222f3
commit 2b1994b98b
8 changed files with 269 additions and 10 deletions

28
redis_om/checks.py Normal file
View file

@ -0,0 +1,28 @@
from functools import lru_cache
from typing import List
from redis_om.connections import get_redis_connection
@lru_cache(maxsize=None)
def get_modules(conn) -> List[str]:
modules = conn.execute_command("module", "list")
return [m[1] for m in modules]
@lru_cache(maxsize=None)
def has_redis_json(conn=None):
if conn is None:
conn = get_redis_connection()
names = get_modules(conn)
return b"ReJSON" in names or "ReJSON" in names
@lru_cache(maxsize=None)
def has_redisearch(conn=None):
if conn is None:
conn = get_redis_connection()
if has_redis_json(conn):
return True
names = get_modules(conn)
return b"search" in names or "search" in names