Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250530) (c39b7370636)
core\session\redis Class Reference
Inheritance diagram for core\session\redis:
core\session\handler

Public Member Functions

 __construct ()
 Create new instance of handler.
 
 abort ()
 Release lock on the session without writing it.
 
 add_session (int $userid)
 Insert new empty session record.
 
 close ()
 Close the session completely.
 
 destroy (string $id)
 Destroy a specific session and delete this session record for this session id.
 
 destroy_all ()
 Destroy all sessions, and delete all the session data.
 
 destroy_by_auth_plugin (string $pluginname)
 Destroy all sessions for a given plugin.
 
 gc (int $max_lifetime=0)
 Periodic timed-out session cleanup.
 
 get_all_sessions ()
 Returns all session records.
 
 get_session_by_sid (string $sid)
 Returns a single session record for this session id.
 
 get_sessions_by_userid (int $userid)
 Returns all the session records for this user id.
 
 init ()
 Init session handler.
 
 open (string $path, string $name)
 Update our session search path to include session name when opened.
 
 read (string $id)
 Read the session data from storage.
 
 requires_write_lock ()
 Has this session been opened with a writelock?
 
 session_exists ($sid)
 Check the backend contains data for this session id.
 
 set_requires_write_lock ($requireswritelock)
 This is called after init() and before start() to indicate whether the session opened should be writable or not.
 
 start ()
 Start the session.
 
 update_session (stdClass $record)
 Update a session record.
 
 update_session (\stdClass $record)
 
 write (string $id, string $data)
 Write the serialized session data to our session store.
 
 write_close ()
 Write the session and release lock.
 

Public Attributes

const COMPRESSION_GZIP = 'gzip'
 Compressor: PHP GZip.
 
const COMPRESSION_NONE = 'none'
 Compressor: none.
 
const COMPRESSION_ZSTD = 'zstd'
 Compressor: PHP Zstandard.
 
string const REDIS_MIN_EXTENSION_VERSION = "5.1.0"
 Minimum extension version.
 
string const REDIS_MIN_SERVER_VERSION = "5.0.0"
 Minimum server version.
 

Protected Member Functions

 destroy_all_expired_sessions (int $purgebefore)
 Clean up all expired sessions.
 
 destroy_expired_user_sessions (int $purgebefore, int $userid)
 Clean up expired sessions.
 
 lock_session ($id)
 Obtain a session lock so we are the only one using it at the moment.
 
 unlock_session ($id)
 Unlock a session.
 

Protected Attributes

int $acquiretimeout = 120
 $acquiretimeout how long to wait for session lock in seconds
 
int $acquirewarn = null
 $acquirewarn how long before warning when waiting for a lock in seconds
 
string $auth = ''
 $auth redis password
 
clock clock $clock
 A clock instance.
 
bool bool $clustermode = false
 $clustermode Redis in cluster mode.
 
int $compressor = self::COMPRESSION_NONE
 $compressor The compressor to use
 
Redis RedisCluster null Redis RedisCluster null $connection = null
 Connection.
 
int int $connectiontimeout = 3
 $connectiontimeout The number of seconds to wait for a connection or response from the Redis server.
 
int $database = 0
 $database the Redis database to store sesions in
 
int int $firstaccesstimeout = 180
 $firstaccesstimeout The initial timeout (seconds) for the first browser access without login.
 
int int $gcbatchsize = 100
 $gcbatchsize The number of redis keys that will be processed each time the garbage collector is executed.
 
array array $host = []
 $host save_path string
 
string $lasthash = null
 $lasthash hash of the session data content
 
int int $lockexpire
 How long to wait in seconds before expiring the lock automatically so that other requests may continue execution.
 
int $lockretry = 100
 $lockretry how long to wait between session lock attempts in ms
 
array $locks = array()
 $locks List of currently held locks by this page.
 
int int $maxretries = 3
 Maximum number of retries for cache store operations.
 
int $port = 6379
 $port The port to connect to
 
array $prefix = ''
 $servers list of servers parsed from save_path
 
boolean $requireswritelock = false
 $requireswritelock does the session need and/or have a lock?
 
int $serializer = Redis::SERIALIZER_PHP
 $serializer The serializer to use
 
string string $sessionkeyprefix = 'session_'
 $sessionkeyprefix the prefix for the session key
 
array $sslopts = []
 $sslopts SSL options, if applicable
 
int $timeout
 $timeout How long sessions live before expiring.
 
string string $userkeyprefix = 'user_'
 $userkeyprefix the prefix for the user key
 

Member Function Documentation

◆ abort()

core\session\handler::abort ( )
inherited

Release lock on the session without writing it.

May not be possible in older versions of PHP. If so, session may be written anyway so that any locks are released.

◆ add_session()

core\session\redis::add_session ( int $userid)

Insert new empty session record.

Parameters
int$userid
Return values
stdClassthe new record

Reimplemented from core\session\handler.

◆ close()

core\session\redis::close ( )

Close the session completely.

We also remove all locks we may have obtained that aren't expired.

Return values
booltrue on success. false on unable to unlock sessions.

◆ destroy()

core\session\redis::destroy ( string $id)

Destroy a specific session and delete this session record for this session id.

Parameters
string$idsession id
Return values
bool

Reimplemented from core\session\handler.

◆ destroy_all()

core\session\redis::destroy_all ( )

Destroy all sessions, and delete all the session data.

Return values
bool

Reimplemented from core\session\handler.

◆ destroy_all_expired_sessions()

core\session\handler::destroy_all_expired_sessions ( int $purgebefore)
protectedinherited

Clean up all expired sessions.

Parameters
int$purgebefore

◆ destroy_by_auth_plugin()

core\session\handler::destroy_by_auth_plugin ( string $pluginname)
inherited

Destroy all sessions for a given plugin.

Typically used when a plugin is disabled or uninstalled, so all sessions (users) for that plugin are logged out.

Parameters
string$pluginnameAuth plugin name.

◆ destroy_expired_user_sessions()

core\session\handler::destroy_expired_user_sessions ( int $purgebefore,
int $userid )
protectedinherited

Clean up expired sessions.

Parameters
int$purgebeforeSessions that have not updated for the last purgebefore timestamp will be removed.
int$userid

◆ gc()

core\session\redis::gc ( int $max_lifetime = 0)

Periodic timed-out session cleanup.

Parameters
int$max_lifetimeSessions that have not updated for the last max_lifetime seconds will be removed.
Return values
int|falseNumber of deleted sessions or false if an error occurred.

Reimplemented from core\session\handler.

◆ get_all_sessions()

core\session\redis::get_all_sessions ( )

Returns all session records.

Return values
Iterator

Reimplemented from core\session\handler.

◆ get_session_by_sid()

core\session\redis::get_session_by_sid ( string $sid)

Returns a single session record for this session id.

Parameters
string$sid
Return values
stdClass

Reimplemented from core\session\handler.

◆ get_sessions_by_userid()

core\session\redis::get_sessions_by_userid ( int $userid)

Returns all the session records for this user id.

Parameters
int$userid
Return values
array

Reimplemented from core\session\handler.

◆ init()

core\session\redis::init ( )

Init session handler.

Reimplemented from core\session\handler.

◆ lock_session()

core\session\redis::lock_session ( $id)
protected

Obtain a session lock so we are the only one using it at the moment.

Parameters
string$idThe session id to lock.
Return values
booltrue when session was locked, exception otherwise.
Exceptions
exceptionWhen we are unable to obtain a session lock.

◆ open()

core\session\redis::open ( string $path,
string $name )

Update our session search path to include session name when opened.

Parameters
string$pathunused session save path. (ignored)
string$nameSession name for this session. (ignored)
Return values
booltrue always as we will succeed.

◆ read()

core\session\redis::read ( string $id)

Read the session data from storage.

Parameters
string$idThe session id to read from storage.
Return values
string|falseThe session data for PHP to process or false.
Exceptions
RedisExceptionwhen we are unable to talk to the Redis server.

◆ requires_write_lock()

core\session\handler::requires_write_lock ( )
inherited

Has this session been opened with a writelock?

Your handler should call this during start() if you support read-only sessions.

Return values
booltrue if session is intended to have a write lock.

◆ session_exists()

core\session\redis::session_exists ( $sid)

Check the backend contains data for this session id.

Note: this is intended to be called from manager::session_exists() only.

Parameters
string$sid
Return values
booltrue if session found.

Reimplemented from core\session\handler.

◆ set_requires_write_lock()

core\session\handler::set_requires_write_lock ( $requireswritelock)
inherited

This is called after init() and before start() to indicate whether the session opened should be writable or not.

This is intentionally captured even if your handler doesn't support non-locking sessions, so that behavior (upon session close) matches closely between handlers.

Parameters
bool$requireswritelocktrue if needs to be open for writing

◆ start()

core\session\handler::start ( )
inherited

Start the session.

Return values
boolsuccess

Reimplemented in core\session\memcached.

◆ unlock_session()

core\session\redis::unlock_session ( $id)
protected

Unlock a session.

Parameters
string$idSession id to be unlocked.

◆ update_session()

core\session\handler::update_session ( stdClass $record)
inherited

Update a session record.

Parameters
stdClass$record
Return values
bool

◆ write()

core\session\redis::write ( string $id,
string $data )

Write the serialized session data to our session store.

Parameters
string$idsession id to write.
string$datasession data
Return values
booltrue on write success, false on failure

◆ write_close()

core\session\handler::write_close ( )
inherited

Write the session and release lock.

If the session was not intentionally opened with a write lock, then we will abort the session instead if able.

Member Data Documentation

◆ $lockexpire

int int core\session\redis::$lockexpire
protected

How long to wait in seconds before expiring the lock automatically so that other requests may continue execution.

$lockexpire


The documentation for this class was generated from the following file: