Skip to content

Commit

Permalink
make code more compact
Browse files Browse the repository at this point in the history
Signed-off-by: wiseaidev <[email protected]>
  • Loading branch information
wiseaidev committed Aug 8, 2022
1 parent dfc7898 commit 42f870d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 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)
4 changes: 2 additions & 2 deletions aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,12 +1195,12 @@ def to_string(s):
step = 2 # Because the result has content
offset = 1 # The first item is the count of total matches.

for i in range(1, len(res), step):
for i in xrange(1, len(res), step):
fields_offset = offset

fields = dict(
dict(
zip(
izip(
map(to_string, res[i + fields_offset][::2]),
map(to_string, res[i + fields_offset][1::2]),
)
Expand Down

0 comments on commit 42f870d

Please sign in to comment.