Changed the way that modules are detected to work with Redis Enterprise and OSS.

This commit is contained in:
Simon Prickett 2022-01-06 15:51:56 +00:00
parent 8a661c9f4c
commit e9fbd56e4e

View file

@ -5,18 +5,19 @@ from aredis_om.connections import get_redis_connection
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
async def get_modules(conn) -> List[str]: async def check_for_command(conn, cmd):
modules = await conn.execute_command("module", "list") try:
return [m[1] for m in modules] cmd_info = await conn.execute_command("command", "info", cmd)
return True
except TypeError:
return False
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
async def has_redis_json(conn=None): async def has_redis_json(conn=None):
if conn is None: if conn is None:
conn = get_redis_connection() conn = get_redis_connection()
names = await get_modules(conn) command_exists = await check_for_command(conn, "json.set")
return b"ReJSON" in names or "ReJSON" in names return command_exists
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
async def has_redisearch(conn=None): async def has_redisearch(conn=None):
@ -24,5 +25,5 @@ async def has_redisearch(conn=None):
conn = get_redis_connection() conn = get_redis_connection()
if has_redis_json(conn): if has_redis_json(conn):
return True return True
names = await get_modules(conn) command_exists = await check_for_command(conn, "ft.search")
return b"search" in names or "search" in names return command_exists