redis-om-python/redis_om/checks.py
Andrew Brookins 2b1994b98b 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.
2021-11-03 12:37:12 -07:00

29 lines
707 B
Python

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