Skip to content

Commit c0f0586

Browse files
authored
Merge pull request #440 from os2display/feature/redis-session-handler
feat: move Symfony sessions to Redis, env-configurable
2 parents 2bd721e + 2f1542c commit c0f0586

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ JWT_SCREEN_REFRESH_TOKEN_TTL=2592000
7272
REDIS_CACHE_PREFIX=DisplayApiService
7373
# Connection string for Redis cache server.
7474
REDIS_CACHE_DSN=redis://redis:6379/0
75+
# Session storage backend, consumed by framework.session.handler_id.
76+
# A `redis://...` DSN makes Symfony auto-build a RedisSessionHandler (with
77+
# its own `sf_s` key prefix, so cache and session keys don't collide on
78+
# the same DB). Empty value = PHP's native file handler; pick that for
79+
# single-pod deployments that don't care about flock-induced tail latency
80+
# or container-restart session survival.
81+
SESSION_HANDLER_DSN=${REDIS_CACHE_DSN}
7582
###< redis ###
7683

7784
###> Http Client ###

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ All notable changes to this project will be documented in this file.
1212
`title`/`description` so it stops inheriting the source-repo defaults.
1313
- Bumped the local dev Redis image from `redis:6` to `redis:8`. Production deployments are unaffected
1414
(they bring their own Redis); Symfony 6.4's cache adapter and the bundled phpredis 6.3 work as-is.
15+
- Switched Symfony session storage to Redis (default `SESSION_HANDLER_DSN=${REDIS_CACHE_DSN}`); set
16+
`SESSION_HANDLER_DSN=` empty to fall back to PHP's native file handler. Removes the per-session
17+
`flock` that serialised parallel session-touching requests and lets sessions survive container
18+
restarts; multi-pod deployments now share session state without sticky routing.
1519

1620
## [3.0.0-rc2] - 2026-05-05
1721

config/packages/framework.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ framework:
99
# Enables session support. Note that the session will ONLY be started if you read or write from it.
1010
# Remove or comment this section to explicitly disable session support.
1111
session:
12-
handler_id: null
12+
# Empty falls back to PHP's native file handler; a `redis://...` DSN
13+
# makes Symfony auto-build a RedisSessionHandler. See SESSION_HANDLER_DSN
14+
# in .env. Redis-backed sessions remove the per-session flock that
15+
# serialises parallel requests on the file handler and survive
16+
# container restarts; local dev gets the same behaviour because the
17+
# default DSN points at the compose Redis.
18+
handler_id: '%env(SESSION_HANDLER_DSN)%'
1319
cookie_secure: auto
1420
cookie_samesite: lax
1521
storage_factory_id: session.storage.factory.native
@@ -33,4 +39,8 @@ when@test:
3339
framework:
3440
test: true
3541
session:
42+
# MockFileSessionStorage keeps tests off Redis; force handler_id
43+
# back to native so the Redis handler service isn't compiled
44+
# against an env that may not point at a reachable Redis.
45+
handler_id: null
3646
storage_factory_id: session.storage.factory.mock_file

0 commit comments

Comments
 (0)