diff --git a/.devcontainer/.env.devcontainer b/.devcontainer/.env.devcontainer index 4cc01ba15..0eac7d10f 100644 --- a/.devcontainer/.env.devcontainer +++ b/.devcontainer/.env.devcontainer @@ -66,7 +66,9 @@ TRUSTED_PROXIES=::1,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 # Redis REDIS_PASSWORD= -REDIS_DNS=redis://127.0.0.1:6379 +REDIS_HOST=127.0.0.1 +REDIS_PORT=6379 +REDIS_DNS=redis://${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT} # S3 storage (optional) S3_KEY= diff --git a/.env.example b/.env.example index 0e384a4ba..9f50c69ad 100644 --- a/.env.example +++ b/.env.example @@ -89,7 +89,9 @@ TRUSTED_PROXIES= # Redis REDIS_PASSWORD=!ChangeThisRedisPass! -REDIS_DNS=redis://${REDIS_PASSWORD}@127.0.0.1:6379 +REDIS_HOST=127.0.0.1 +REDIS_PORT=6379 +REDIS_DNS=redis://${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT} # Or when using Redis Socket: #REDIS_DNS=redis://${REDIS_PASSWORD}/var/run/redis/redis-server.sock # Or socket without password: diff --git a/.env.example_docker b/.env.example_docker index ad57c4538..c896a7acc 100644 --- a/.env.example_docker +++ b/.env.example_docker @@ -93,8 +93,10 @@ HCAPTCHA_SECRET= TRUSTED_PROXIES= # Valkey -VALKEY_PASSWORD=!ChangeThisValkeyPass! -REDIS_DNS=redis://${VALKEY_PASSWORD}@valkey:6379 +REDIS_PASSWORD=!ChangeThisValkeyPass! +REDIS_HOST=valkey +REDIS_PORT=6379 +REDIS_DNS="redis://${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}" # S3 storage (optional) S3_KEY= diff --git a/compose.yaml b/compose.yaml index 27c2b318d..623683f87 100644 --- a/compose.yaml +++ b/compose.yaml @@ -86,7 +86,7 @@ services: image: docker.io/valkey/valkey:trixie restart: unless-stopped user: ${MBIN_USER} - command: valkey-server /valkey.conf --requirepass ${VALKEY_PASSWORD} + command: valkey-server /valkey.conf --requirepass ${REDIS_PASSWORD} healthcheck: test: ['CMD', 'valkey-cli', 'ping'] volumes: diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 980040270..147238c5d 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -24,11 +24,20 @@ framework: # We set our cookie session lifetime to the same value as remember_me token. # More info: https://symfony.com/doc/current/session.html#session-idle-time-keep-alive session: - handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler + # previous + #handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler + # transition + handler_id: App\MigratePdoToRedisSessionHandler + # new + #handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler cookie_secure: auto cookie_samesite: lax cookie_lifetime: 10512000 # 4 months long lifetime storage_factory_id: session.storage.factory.native + # see: https://symfony.com/doc/7.4/session.html#configuring-garbage-collection + # debian sets this value to 0, so since we cannot control that, make the garbage collection a 1/1000 chance + gc_probability: 1 + gc_divisor: 1000 http_client: default_options: diff --git a/config/services.yaml b/config/services.yaml index 7dd660627..31feac734 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -289,3 +289,18 @@ services: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler: arguments: - '%env(DATABASE_URL)%' + + Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler: + arguments: + - '@Redis' + + Redis: + class: Redis + calls: + - connect: + - '%env(REDIS_HOST)%' + - '%env(int:REDIS_PORT)%' + + # uncomment the following if your Redis server requires a password + #- auth: + # - '%env(REDIS_PASSWORD)%' diff --git a/src/MigratePdoToRedisSessionHandler.php b/src/MigratePdoToRedisSessionHandler.php new file mode 100644 index 000000000..ddb5b9ae8 --- /dev/null +++ b/src/MigratePdoToRedisSessionHandler.php @@ -0,0 +1,17 @@ +