fix: Improve handling of Redis URL

This change replaces the creation of Redis URL, from a simple string
interpolation, to using `yarl.URL`. The main benefit, besides not
forgetting to set all five different variables on every Redis client
initialization, is that user credentials are correctly URL-encoded, if
present.

Up until now, if a password had special characters, it could break the
generated URL.

This change also introduces support for a `REDIS_SSL` setting, which
allows the user to specify if the Redis connection should use SSL or not.
This commit is contained in:
Michael Manganiello
2024-10-11 21:41:19 -03:00
parent 36c77d51c8
commit b81fbc5820
6 changed files with 224 additions and 136 deletions

View File

@@ -1,5 +1,5 @@
import socketio # type: ignore
from handler.redis_handler import redis_url
from config import REDIS_URL
class SocketHandler:
@@ -9,7 +9,7 @@ class SocketHandler:
async_mode="asgi",
logger=False,
engineio_logger=False,
client_manager=socketio.AsyncRedisManager(redis_url),
client_manager=socketio.AsyncRedisManager(str(REDIS_URL)),
)
self.socket_app = socketio.ASGIApp(