VuFind API Documentation

Redis extends AbstractBase
in package
Uses RetryTrait

Redis session handler

Tags
category

VuFind

author

Veros Kaplan cpk-dev@mzk.cz

author

Josef Moravec moravec@mzk.cz

author

Ere Maijala ere.maijala@helsinki.fi

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

Table of Contents

$connection  : Credis_Client
Redis connection
$dbServiceManager  : PluginManager
Database service plugin manager
$lifetime  : int
Session lifetime in seconds
$redisVersion  : int
Redis version
$retryOptions  : array<string|int, mixed>
Retry options
$tableManager  : PluginManager
Database table plugin manager
$writesDisabled  : bool
Whether writes are disabled, i.e. any changes to the session are not written to the storage
__construct()  : mixed
Constructor
close()  : bool
Close function, this works like a destructor in classes and is executed when the session operation is done.
destroy()  : bool
The destroy handler, this is executed when a session is destroyed with session_destroy() and takes the session id as its only parameter.
disableWrites()  : void
Disable session writing, i.e. make it read-only
enableWrites()  : void
Enable session writing (default)
gc()  : int|false
The garbage collector, this is executed when the session garbage collector is executed and takes the max session lifetime as its only parameter.
getDbService()  : T
Get a database service object.
getDbServiceManager()  : PluginManager
Get the service plugin manager. Throw an exception if it is missing.
getDbTable()  : Gateway
Get a database table object.
getDbTableManager()  : PluginManager
Get the table plugin manager. Throw an exception if it is missing.
open()  : bool
Open function, this works like a constructor in classes and is executed when the session is being opened.
read()  : string
Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read.
setDbServiceManager()  : void
Set the service plugin manager.
setDbTableManager()  : void
Set the table plugin manager.
write()  : bool
Write function that is called when session data is to be saved.
callWithRetry()  : mixed
Call a method and retry the call if an exception is thrown
getBackoffDuration()  : int
Get the delay before a try
saveSession()  : bool
Write function that is called when session data is to be saved.
shouldRetry()  : bool
Check if the call needs to be retried

Properties

$connection

Redis connection

protected Credis_Client $connection

$lifetime

Session lifetime in seconds

protected int $lifetime = 3600

$redisVersion

Redis version

protected int $redisVersion = 3

$retryOptions

Retry options

protected array<string|int, mixed> $retryOptions = [ 'retryCount' => 5, // number of retries (set to 0 to disable) 'firstBackoff' => 0, // backoff (delay) before first retry // (milliseconds) 'subsequentBackoff' => 200, // backoff (delay) before subsequent retries // (milliseconds) 'exponentialBackoff' => true, // whether to use exponential backoff 'maximumBackoff' => 1000, ]

$writesDisabled

Whether writes are disabled, i.e. any changes to the session are not written to the storage

protected bool $writesDisabled = false

Methods

__construct()

Constructor

public __construct(Credis_Client $connection[, Config $config = null ]) : mixed
Parameters
$connection : Credis_Client

Redis connection object

$config : Config = null

Session configuration ([Session] section of config.ini)

Return values
mixed

close()

Close function, this works like a destructor in classes and is executed when the session operation is done.

public close() : bool
Return values
bool

destroy()

The destroy handler, this is executed when a session is destroyed with session_destroy() and takes the session id as its only parameter.

public destroy(string $sessId) : bool
Parameters
$sessId : string

The session ID to destroy

Return values
bool

disableWrites()

Disable session writing, i.e. make it read-only

public disableWrites() : void
Return values
void

enableWrites()

Enable session writing (default)

public enableWrites() : void
Return values
void

gc()

The garbage collector, this is executed when the session garbage collector is executed and takes the max session lifetime as its only parameter.

public gc(int $sessMaxLifetime) : int|false
Parameters
$sessMaxLifetime : int

Maximum session lifetime.

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
int|false

getDbService()

Get a database service object.

public getDbService(class-string<\VuFind\Db\Service\T> $name) : T
Parameters
$name : class-string<\VuFind\Db\Service\T>

Name of service to retrieve

Tags
template

T

Return values
T

getDbTable()

Get a database table object.

public getDbTable(string $table) : Gateway
Parameters
$table : string

Table to load.

Return values
Gateway

open()

Open function, this works like a constructor in classes and is executed when the session is being opened.

public open(string $sess_path, string $sess_name) : bool
Parameters
$sess_path : string

Session save path

$sess_name : string

Session name

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
bool

read()

Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read.

public read(string $sessId) : string
Parameters
$sessId : string

The session ID to read

Return values
string

write()

Write function that is called when session data is to be saved.

public write(string $sessId, string $data) : bool
Parameters
$sessId : string

The current session ID

$data : string

The session data to write

Return values
bool

callWithRetry()

Call a method and retry the call if an exception is thrown

protected callWithRetry(callable $callback[, callable|null $statusCallback = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$callback : callable

Method to call

$statusCallback : callable|null = null

Status callback called before retry and after a successful retry. The callback gets the attempt number and either an exception if an error occurred or null if the request succeeded after retries.

$options : array<string|int, mixed> = []

Optional options to override defaults in $this->retryOptions. Options can also include a retryableExceptionCallback for a callback that gets the attempt number and exception as parameters and returns true if the call can be retried or false if not.

Return values
mixed

getBackoffDuration()

Get the delay before a try

protected getBackoffDuration(int $attempt, array<string|int, mixed> $options) : int
Parameters
$attempt : int

Attempt number

$options : array<string|int, mixed>

Current options

Return values
int

milliseconds

saveSession()

Write function that is called when session data is to be saved.

protected saveSession(string $sessId, string $data) : bool
Parameters
$sessId : string

The current session ID

$data : string

The session data to write

Return values
bool

shouldRetry()

Check if the call needs to be retried

protected shouldRetry(int $attempt, array<string|int, mixed> $options) : bool
Parameters
$attempt : int

Failed attempt number

$options : array<string|int, mixed>

Current options

Return values
bool

Search results