From 1b3accd0ae87336f769c4eb913541c8eff282575 Mon Sep 17 00:00:00 2001 From: wiseaidev Date: Sun, 7 Aug 2022 12:54:09 +0300 Subject: [PATCH] make code more compact Signed-off-by: wiseaidev --- aredis_om/checks.py | 6 ++---- aredis_om/connections.py | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/aredis_om/checks.py b/aredis_om/checks.py index ea59629a..a5b3eede 100644 --- a/aredis_om/checks.py +++ b/aredis_om/checks.py @@ -7,14 +7,12 @@ @lru_cache(maxsize=None) async def check_for_command(conn, cmd): cmd_info = await conn.execute_command("command", "info", cmd) - return None not in cmd_info + return all(cmd_info) @lru_cache(maxsize=None) async def has_redis_json(conn=None): - if not conn: - conn = get_redis_connection() - command_exists = await check_for_command(conn, "json.set") + command_exists = await check_for_command(conn or get_redis_connection(), "json.set") return command_exists diff --git a/aredis_om/connections.py b/aredis_om/connections.py index 940682c8..6ff5d7ba 100644 --- a/aredis_om/connections.py +++ b/aredis_om/connections.py @@ -9,11 +9,9 @@ def get_redis_connection(**kwargs) -> aioredis.Redis: # If someone passed in a 'url' parameter, or specified a REDIS_OM_URL # environment variable, we'll create the Redis client from the URL. - url = kwargs.pop("url", URL) - if url: - return aioredis.Redis.from_url(url, **kwargs) - + if not kwargs.get("url", None) and URL: + kwargs["url"] = URL # Decode from UTF-8 by default - if "decode_responses" not in kwargs: + if not kwargs.get("decode_responses", None): kwargs["decode_responses"] = True - return aioredis.Redis(**kwargs) + return aioredis.from_url(**kwargs)