Skip to content

Commit 1b3accd

Browse files
committed
make code more compact
Signed-off-by: wiseaidev <[email protected]>
1 parent dfc7898 commit 1b3accd

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

aredis_om/checks.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
@lru_cache(maxsize=None)
88
async def check_for_command(conn, cmd):
99
cmd_info = await conn.execute_command("command", "info", cmd)
10-
return None not in cmd_info
10+
return all(cmd_info)
1111

1212

1313
@lru_cache(maxsize=None)
1414
async def has_redis_json(conn=None):
15-
if not conn:
16-
conn = get_redis_connection()
17-
command_exists = await check_for_command(conn, "json.set")
15+
command_exists = await check_for_command(conn or get_redis_connection(), "json.set")
1816
return command_exists
1917

2018

aredis_om/connections.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
def get_redis_connection(**kwargs) -> aioredis.Redis:
1010
# If someone passed in a 'url' parameter, or specified a REDIS_OM_URL
1111
# environment variable, we'll create the Redis client from the URL.
12-
url = kwargs.pop("url", URL)
13-
if url:
14-
return aioredis.Redis.from_url(url, **kwargs)
15-
12+
if not kwargs.get("url", None) and URL:
13+
kwargs["url"] = URL
1614
# Decode from UTF-8 by default
17-
if "decode_responses" not in kwargs:
15+
if not kwargs.get("decode_responses", None):
1816
kwargs["decode_responses"] = True
19-
return aioredis.Redis(**kwargs)
17+
return aioredis.from_url(**kwargs)

0 commit comments

Comments
 (0)