Skip to content

Commit

Permalink
make code more compact
Browse files Browse the repository at this point in the history
Signed-off-by: wiseaidev <business@wiseai.dev>
  • Loading branch information
wiseaidev committed Aug 7, 2022
1 parent dfc7898 commit 1b3accd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 2 additions & 4 deletions aredis_om/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 4 additions & 6 deletions aredis_om/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1b3accd

Please sign in to comment.