RedisSessionBackend
class \
- Implements
- SessionBackendInterface, HashableSessionBackendInterface, LoggerAwareInterface
- Uses
- LoggerAwareTrait
This session backend takes these optional configuration options: 'hostname' (default '127.0.0.1'), 'database' (default 0), 'port' (default 3679), 'username' (no default value) and 'password' (no default value).
Tags
Table of Contents
Interfaces
- SessionBackendInterface
- Interface SessionBackendInterface
- HashableSessionBackendInterface
- LoggerAwareInterface
Properties
- $applicationIdentifier : string
- Used as instance independent identifier (e.g. if multiple installations write into the same database)
- $configuration : array
- $connected : bool
- Indicates whether the server is connected
- $identifier : string
- $redis : Redis
Methods
- collectGarbage() : void
- Garbage Collection
- get() : array
- Read session data
- getAll() : array
- List all sessions
- hash() : string
- initialize() : void
- Initializes the session backend
- remove() : bool
- Delete a session record
- set() : array
- Write session data. This method prevents overriding existing session data.
- update() : array
- Updates the session data.
- validateConfiguration() : void
- Checks if the configuration is valid
- getAuthentication() : array|string|null
- getSessionKeyName() : string
- initializeConnection() : void
- Initializes the redis backend
- logRedisCommandFailure() : void
Properties
$applicationIdentifier
Used as instance independent identifier (e.g. if multiple installations write into the same database)
protected
string
$applicationIdentifier
= ''
$configuration
protected
array
$configuration
= []
$connected
Indicates whether the server is connected
protected
bool
$connected
= false
$identifier
protected
string
$identifier
$redis
protected
Redis
$redis
Methods
collectGarbage()
Garbage Collection
public
collectGarbage(int $maximumLifetime[, int $maximumAnonymousLifetime = 0 ]) : void
Parameters
- $maximumLifetime : int
-
maximum lifetime of authenticated user sessions, in seconds.
- $maximumAnonymousLifetime : int = 0
-
maximum lifetime of non-authenticated user sessions, in seconds. If set to 0, nothing is collected.
get()
Read session data
public
get(string $sessionId) : array
Parameters
- $sessionId : string
Tags
Return values
array —Returns the session data
getAll()
List all sessions
public
getAll() : array
Return values
array —Return a list of all user sessions. The list may be empty.
hash()
public
hash(string $sessionId) : string
Parameters
- $sessionId : string
Return values
stringinitialize()
Initializes the session backend
public
initialize(string $identifier, array $configuration) : void
Parameters
- $identifier : string
-
Name of the session type, e.g. FE or BE
- $configuration : array
Internal
To be used only by SessionManager
remove()
Delete a session record
public
remove(string $sessionId) : bool
Parameters
- $sessionId : string
Return values
bool —true if the session was deleted, false it session could not be found
set()
Write session data. This method prevents overriding existing session data.
public
set(string $sessionId, array $sessionData) : array
ses_id will always be set to $sessionId and overwritten if existing in $sessionData This method updates ses_tstamp automatically
Parameters
- $sessionId : string
- $sessionData : array
Tags
Return values
array —The newly created session record.
update()
Updates the session data.
public
update(string $sessionId, array $sessionData) : array
ses_id will always be set to $sessionId and overwritten if existing in $sessionData This method updates ses_tstamp automatically
Parameters
- $sessionId : string
- $sessionData : array
-
The session data to update. Data may be partial.
Tags
Return values
array —$sessionData The newly updated session record.
validateConfiguration()
Checks if the configuration is valid
public
validateConfiguration() : void
Internal
To be used only by SessionManager
Tags
getAuthentication()
protected
getAuthentication() : array|string|null
Return values
array|string|nullgetSessionKeyName()
protected
getSessionKeyName(string $sessionId) : string
Parameters
- $sessionId : string
Return values
stringinitializeConnection()
Initializes the redis backend
protected
initializeConnection() : void
Tags
logRedisCommandFailure()
protected
logRedisCommandFailure(string $command, string $method) : void
Parameters
- $command : string
- $method : string