mirror of
https://github.com/simple-login/app.git
synced 2024-11-14 08:01:13 +01:00
7f9ce5641f
* Feat: Added parallel limiter to prevent sqlalchemy transaction issues * Remove logs * Moved initialization to its own file * Throw exception * Added test * Add redis to gh actions * Added v6 to the name * Removed debug prints Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
23 lines
842 B
Python
23 lines
842 B
Python
import flask
|
|
import limits.storage
|
|
|
|
from app.parallel_limiter import set_redis_concurrent_lock
|
|
from app.session import RedisSessionStore
|
|
|
|
|
|
def initialize_redis_services(app: flask.Flask, redis_url: str):
|
|
|
|
if redis_url.startswith("redis://"):
|
|
storage = limits.storage.RedisStorage(redis_url)
|
|
app.session_interface = RedisSessionStore(storage.storage, storage.storage, app)
|
|
set_redis_concurrent_lock(storage)
|
|
elif redis_url.startswith("redis+sentinel://"):
|
|
storage = limits.storage.RedisSentinelStorage(redis_url)
|
|
app.session_interface = RedisSessionStore(
|
|
storage.storage, storage.storage_slave, app
|
|
)
|
|
set_redis_concurrent_lock(storage)
|
|
else:
|
|
raise RuntimeError(
|
|
f"Tried to set_redis_session with an invalid redis url: ${redis_url}"
|
|
)
|