Skip to content

RedisSessionPersistence

Redis-backed SessionPersistenceInterface for SessionManager.

One string key per session id, written with SETEX so Redis itself expires stale sessions — no GC pass needed, unlike the PDO/file backends.

final class RedisSessionPersistence implements SessionPersistenceInterface

ImplementsSessionPersistenceInterface
SourceRedisSessionPersistence.php

public function __construct(ClientInterface $redis, string $prefix = 'session:', int $ttl = 1440, SessionCodecInterface $codec = new SessionCodec(…)): mixed

ParameterTypeDescription
$redisClientInterface
$prefixstring
$ttlint
$codecSessionCodecInterface

Returns mixed

MethodDescription
delete(string $sid): voidDeletes the session’s Redis key.
load(string $sid): ?arrayReads the session’s Redis key and decodes it through the codec.
save(string $sid, array<string, mixed> $data): void

public function delete(string $sid): void

Deletes the session’s Redis key.

Deleting a key that is absent or already expired is a no-op on Redis’s side, so this reports nothing back either way.

ParameterTypeDescription
$sidstring

public function load(string $sid): ?array

Reads the session’s Redis key and decodes it through the codec.

Returns null when the key is missing or expired — Redis expires it on its own, so an aged-out session is simply absent — and when the value is empty or not a string.

ParameterTypeDescription
$sidstring

Returns ?``array

public function save(string $sid, array<string, mixed> $data): void

ParameterTypeDescription
$sidstring
$dataarray``<``string``, ``mixed``>