redis-om-python/aredis_om/checks.py

29 lines
744 B
Python
Raw Normal View History

from functools import lru_cache
from typing import List
2021-11-10 00:59:10 +01:00
from aredis_om.connections import get_redis_connection
@lru_cache(maxsize=None)
2021-11-10 00:59:10 +01:00
async def get_modules(conn) -> List[str]:
modules = await conn.execute_command("module", "list")
return [m[1] for m in modules]
@lru_cache(maxsize=None)
2021-11-10 00:59:10 +01:00
async def has_redis_json(conn=None):
if conn is None:
conn = get_redis_connection()
2021-11-10 00:59:10 +01:00
names = await get_modules(conn)
return b"ReJSON" in names or "ReJSON" in names
@lru_cache(maxsize=None)
2021-11-10 00:59:10 +01:00
async def has_redisearch(conn=None):
if conn is None:
conn = get_redis_connection()
if has_redis_json(conn):
return True
2021-11-10 00:59:10 +01:00
names = await get_modules(conn)
return b"search" in names or "search" in names