Skip to content

Commit 6038f18

Browse files
committed
Improvements
1 parent c33ed86 commit 6038f18

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

session/database.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ First, define a Symfony service for the connection to the Redis server:
7676
// ->addMethodCall('auth', ['%env(REDIS_PASSWORD)%'])
7777
;
7878
79-
Now pass this Redis connection as an argument of the service associated to the
80-
:class:`Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler`:
79+
Now pass this ``\Redis`` connection as an argument of the service associated to the
80+
:class:`Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler`.
81+
This argument can also be a ``\RedisArray``, ``\RedisCluster``, ``\Predis\Client``,
82+
and ``RedisProxy``:
8183

8284
.. configuration-block::
8385

@@ -155,7 +157,16 @@ configuration option to tell Symfony to use this service as the session handler:
155157
],
156158
]);
157159
158-
That's all! Symfony will now use your Redis server to read and write the session data.
160+
That's all! Symfony will now use your Redis server to read and write the session
161+
data. The main drawback of this solution is that Redis does not perform session
162+
locking, so you can face *race conditions* when accessing sessions. For example,
163+
you may see an *"Invalid CSRF token"* error because two requests were made in
164+
parallel and only the first one stored the CSRF token in the session.
165+
166+
.. seealso::
167+
168+
If you use Memcached instead of Redis, follow a similar approach but replace
169+
``RedisSessionHandler`` by :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`.
159170

160171
Store Sessions in a Relational Database (MySQL, PostgreSQL)
161172
-----------------------------------------------------------

0 commit comments

Comments
 (0)