redis-om-python/aredis_om/checks.py

29 lines
751 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)
async def check_for_command(conn, cmd):
2022-01-06 22:10:53 +01:00
cmd_info = await conn.execute_command("command", "info", cmd)
2022-01-13 18:10:51 +01:00
return None not in cmd_info
2022-01-13 18:08:46 +01:00
@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()
command_exists = await check_for_command(conn, "json.set")
return command_exists
2022-01-13 18:08:46 +01:00
@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
command_exists = await check_for_command(conn, "ft.search")
return command_exists