-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
|
||
import redis.asyncio as redis | ||
from redis.asyncio.connection import parse_url | ||
|
||
from sam import config | ||
|
||
|
||
@contextlib.asynccontextmanager | ||
async def async_redis_client(url): | ||
"""Asynchronous context manager to get a Redis client.""" | ||
connection_config = parse_url(url) | ||
if connection_config.get("connection_class") == redis.SSLConnection: | ||
connection_config["ssl_cert_reqs"] = config.REDIS_CERT_REQS | ||
|
||
client = await redis.Redis(**connection_config) | ||
try: | ||
yield client | ||
finally: | ||
await client.aclose() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters