RedisSessionHandler
class RedisSessionHandler implements CanManageUserSessions, SessionHandlerInterface
Traits
Constants
| protected ENVELOPE_FAMILY |
Envelope values mirrored by the Lua ownership parser below. |
| protected ENVELOPE_VERSION |
|
| protected OWNER_DIGEST_LENGTH |
|
| protected ENVELOPE_HEADER_LENGTH |
|
| protected USER_INDEX_PREFIX |
User-index fragments mirrored where Lua constructs dynamic owner keys. |
| protected USER_INDEX_SUFFIX |
|
| protected REDIS_OWNER_CONTEXT_KEY_PREFIX |
Context key prefix for owners observed from Redis Cluster payloads. |
| protected LUA_OWNER_OF |
|
| protected LUA_VALID_METADATA |
|
| protected WRITE_SCRIPT |
|
| protected DESTROY_SCRIPT |
|
| protected DESTROY_USER_SESSION_SCRIPT |
|
| protected DESTROY_USER_SESSIONS_SCRIPT |
|
| protected CLUSTER_WRITE_SCRIPT |
|
| protected CLUSTER_UPDATE_INDEX_SCRIPT |
|
| protected CLUSTER_DESTROY_SCRIPT |
|
Methods
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Validate an authentication provider supplied to the handler.
Validate and deduplicate session identifiers supplied to the handler.
Create a new Redis session handler instance.
Open the session.
Close the session.
Create a new session ID.
Determine if the session ID exists.
Read the session data.
Write the session data.
Write a tracked session to Redis Cluster.
Update a session field in a Redis Cluster user index.
Destroy the given session.
Perform session garbage collection.
Determine if the handler supports user session management.
Get the active sessions for the given user.
Destroy an active session belonging to the given user.
Destroy the active sessions belonging to the given user.
Destroy user sessions across Redis Cluster slots.
Clean fields from a user's session index.
Get a payload key.
Get a user session index key.
Get the full physical prefix used for dynamically constructed Lua keys.
Get the configured session lifetime in seconds.
Hash a provider-qualified user identifier for use in Redis keys and envelopes.
Get the proven owner from a stored session value.
Strip a valid ownership envelope from a stored session payload.
Determine if a value is a valid owner digest.
Probe and remember the owner of a Redis Cluster session payload.
Get an owner observed for a Redis Cluster session.
Remember a Redis Cluster session owner for the current coroutine.
Get this handler's Redis Cluster owner observations.
Forget this handler's Redis Cluster owner observations.
Get this handler's Redis Cluster owner context key.
Encode metadata for a tracked session write.
Decode and validate tracked session metadata.
Get the current request IP address.
Get the current request user agent.
Parse the ownership transition returned by the cluster write script.
Parse a cluster payload deletion result.
Reset this handler's observed owners when it is cloned.
Details
in
InteractsWithTime at line 17
protected int
secondsUntil(DateInterval|DateTimeInterface|int $delay)
Get the number of seconds until the given DateTime.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
in
InteractsWithTime at line 47
protected DateTimeInterface|int
parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)
If the given value is an interval, convert it to a DateTime instance.
in
InteractsWithTime at line 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 71
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
in
ValidatesUserSessionArguments at line 15
protected void
validateAuthProvider(string $authProvider)
Validate an authentication provider supplied to the handler.
in
ValidatesUserSessionArguments at line 28
protected array
normalizeSessionIds(array $sessionIds)
Validate and deduplicate session identifiers supplied to the handler.
at line 285
__construct(Factory $redis, string $connection, string $prefix, int $minutes, bool $trackUserSessions = false, Container|null $container = null)
Create a new Redis session handler instance.
at line 299
bool
open(string $savePath, string $sessionName)
Open the session.
at line 307
bool
close()
Close the session.
at line 315
string
create_sid()
Create a new session ID.
at line 323
bool
validateId(string $id)
Determine if the session ID exists.
at line 333
string
read(string $sessionId)
Read the session data.
at line 356
bool
write(string $sessionId, string $data)
Write the session data.
at line 426
protected bool
writeCluster(RedisConnection $connection, string $sessionId, string $data, string $identityState, string $resolvedOwner, int $lastActivity, int $expiresAt, bool $hasFreshMetadata, string $metadata)
Write a tracked session to Redis Cluster.
at line 494
protected bool
updateClusterIndex(RedisConnection $connection, string $owner, string $sessionId, int $expiresAt, int $lastActivity, bool $hasFreshMetadata, string $metadata)
Update a session field in a Redis Cluster user index.
at line 526
bool
destroy(string $sessionId)
Destroy the given session.
at line 570
int
gc(int $lifetime)
Perform session garbage collection.
at line 578
bool
supportsUserSessionManagement()
Determine if the handler supports user session management.
at line 588
Collection
userSessions(string $authProvider, int|string $userId)
Get the active sessions for the given user.
at line 647
bool
destroyUserSession(string $authProvider, int|string $userId, string $sessionId)
Destroy an active session belonging to the given user.
at line 692
int
destroyUserSessions(string $authProvider, int|string $userId, array $except = [])
Destroy the active sessions belonging to the given user.
at line 725
protected int
destroyUserSessionsInCluster(RedisConnection $connection, string $owner, array $except)
Destroy user sessions across Redis Cluster slots.
at line 794
protected void
cleanUserIndex(RedisConnection $connection, string $owner, array $sessionIds)
Clean fields from a user's session index.
at line 811
protected string
payloadKey(string $sessionId)
Get a payload key.
at line 819
protected string
userIndexKey(string $owner)
Get a user session index key.
at line 827
protected string
physicalPrefix(RedisConnection $connection)
Get the full physical prefix used for dynamically constructed Lua keys.
at line 835
protected int
lifetimeInSeconds()
Get the configured session lifetime in seconds.
at line 843
protected string
ownerDigest(string $authProvider, string $userId)
Hash a provider-qualified user identifier for use in Redis keys and envelopes.
at line 857
protected string
ownerFromStoredValue(string $value)
Get the proven owner from a stored session value.
at line 872
protected string
payloadFromStoredValue(string $value)
Strip a valid ownership envelope from a stored session payload.
at line 888
protected bool
validOwnerDigest(string $owner)
Determine if a value is a valid owner digest.
at line 896
protected string
probeOwner(RedisConnection $connection, string $sessionId)
Probe and remember the owner of a Redis Cluster session payload.
at line 913
protected string|null
observedOwner(string $sessionId)
Get an owner observed for a Redis Cluster session.
at line 923
protected void
rememberOwner(string $sessionId, string $owner)
Remember a Redis Cluster session owner for the current coroutine.
at line 936
protected array
ownerObservations()
Get this handler's Redis Cluster owner observations.
at line 944
protected void
forgetOwnerObservations()
Forget this handler's Redis Cluster owner observations.
at line 952
protected string
ownerContextKey()
Get this handler's Redis Cluster owner context key.
at line 962
protected string
encodeMetadata(int $lastActivity, bool $hasFreshMetadata)
Encode metadata for a tracked session write.
at line 976
protected array|null
decodeMetadata(string $value)
Decode and validate tracked session metadata.
at line 1005
protected string|null
ipAddress()
Get the current request IP address.
at line 1013
protected string
userAgent()
Get the current request user agent.
at line 1030
protected array
parseOwnerTransition(mixed $value)
Parse the ownership transition returned by the cluster write script.
A status of zero means the second element is the actual current owner and the third element is empty because no payload mutation occurred.
at line 1052
protected array
parseDestroyResult(mixed $value)
Parse a cluster payload deletion result.
at line 1071
protected mixed
withConnection(Closure $callback)
Execute an operation on a pinned raw Redis connection.
at line 1090
void
__clone()
Reset this handler's observed owners when it is cloned.
PHP reuses freed object IDs, so a clone can land on a released handler's ID and must not inherit its owner observations.