PHP Class Bravo3\Orm\Drivers\Redis\RedisDriver

Inheritance: implements Bravo3\Orm\Drivers\DriverInterface, implements Bravo3\Orm\Drivers\PubSubDriverInterface, use trait Bravo3\Orm\Traits\DebugTrait, use trait Bravo3\Orm\Traits\PubSubTrait, use trait Bravo3\Orm\Drivers\Common\StandardIdValidatorTrait
Datei anzeigen Open project: bravo3/orm Class Usage Examples

Protected Properties

Property Type Description
$client Predis\Client
$initial_retry_delay integer Initial retry delay between failing $client commands.
$max_connection_retries integer Maximum number of Predis connection retries to occur if redis server doesn't respond.
$retry_delay_coefficient integer Get/Write commands that fails will be retried again upto $max_connection_retries times with delays between each retry.
$score_normaliser Bravo3\Orm\Services\ScoreNormaliser
$unit_of_work Bravo3\Orm\Drivers\Common\UnitOfWork

Public Methods

Method Description
__construct ( mixed $params = null, mixed $options = null, mixed $sentinel_params = null, Predis\ClientInterface $client = null ) Create a new Redis driver
addMultiValueIndex ( string $key, string | array $value ) : void Add one or many values to a set index
addRef ( string $key, Ref $ref ) : void Add a ref to an entity
addSortedIndex ( string $key, mixed $score, string $value ) : void Add or update an item in a sorted index
calculateRetryDelay ( integer $retry_iteration ) : integer Calculate a retry delay to be used in the clientCmd() function to delay failing operations to $client.
clearMultiValueIndex ( string $key ) : void Clear all values from a set index
clearRefs ( string $key ) : void Clear all refs from an entity (delete a ref list)
clearSingleValueIndex ( string $key ) : string Clear the value of a key-value index
clearSortedIndex ( string $key ) : void Clear an entire sorted index
debugLog ( string $msg ) : void Create a debug log
delete ( string $key ) : void Delete a primitive document
flush ( ) : void Execute the current unit of work
getInitialRetryDelay ( ) : integer Gets the Initial retry delay between failing $client commands.
getMaxConnectionRetries ( ) : integer Gets the Maximum number of Predis connection retries to occur if redis server doesn't respond.
getMultiValueIndex ( string $key ) : string[] Get a list of all values on a set index
getPreferredKeyScheme ( ) : Bravo3\Orm\KeySchemes\KeySchemeInterface Get the drivers preferred key scheme
getRefs ( string $key ) : Ref[] Get all refs to an entity
getRetryDelayCoefficient ( ) : integer Returns the current retry delay coefficient set, which is the delay between each retry may happen if the requests to $client fails.
getSingleValueIndex ( string $key ) : string Get the value of a key-value index
getSortedIndex ( string $key, boolean $reverse = false, integer $start = null, integer $stop = null ) : string[] Get a range values in a sorted index
getSortedIndexSize ( string $key ) : integer Get the size of a sorted index, without any filters applied
isPubSubSupported ( ) : boolean Checks if the driver supports publish/subscribe pattern.
listenToPubSub ( callable $callback ) : void Start listening to subscribed channels of the Redis PubSub mechanism.
persist ( string $key, SerialisedData $data, integer $ttl = null ) : void Persist some primitive data
publishMessage ( string $channel, string $message ) : integer Uses Redis PubSub implementation to push messages to the channel specified.
purge ( ) : void Purge the current unit of work, clearing any unexecuted commands
removeMultiValueIndex ( string $key, string | array $value ) : void Remove one or more values from a set index
removeRef ( string $key, Ref $ref ) : void Remove a ref from an entity
removeSortedIndex ( string $key, string $value ) : void Remove an item from a sorted index
retrieve ( string $key ) : SerialisedData Retrieve an object, throwing an exception if not found
scan ( string $key ) : string[] Scan key-value indices and return the value of all matching keys
setInitialRetryDelay ( integer $initial_retry_delay ) : self Sets the Initial retry delay between failing $client commands.
setMaxConnectionRetries ( integer $max_connection_retries ) : self Sets the Maximum number of Predis connection retries to occur if redis server doesn't respond.
setRetryDelayCoefficient ( integer $delay_coefficient ) : RedisDriver Set retry delay between $client command retries.
setSingleValueIndex ( string $key, string $value ) : void Set a key-value index

Protected Methods

Method Description
getScoreNormaliser ( ) : ScoreNormaliser Lazy-loading score normaliser

Private Methods

Method Description
clientCmd ( string $cmd, array | callable $params, integer $retry_iteration ) : mixed A wrapper function to wrap Redis commands which go to Predis Client in order to replay them if server connection issues occur.
flushMulti ( ) Execute all items in the work queue in a single transaction
flushSingle ( ) Execute the next item in the work queue
getPredisCommand ( Command $command ) : Predis\Command\CommandInterface Build a Predis command from a Command object

Method Details

__construct() public method

Create a new Redis driver
public __construct ( mixed $params = null, mixed $options = null, mixed $sentinel_params = null, Predis\ClientInterface $client = null )
$params mixed
$options mixed
$sentinel_params mixed
$client Predis\ClientInterface

addMultiValueIndex() public method

Add one or many values to a set index
public addMultiValueIndex ( string $key, string | array $value ) : void
$key string
$value string | array
return void

addRef() public method

Add a ref to an entity
public addRef ( string $key, Ref $ref ) : void
$key string Entity ref key
$ref Bravo3\Orm\Drivers\Common\Ref Reference to add
return void

addSortedIndex() public method

Add or update an item in a sorted index
public addSortedIndex ( string $key, mixed $score, string $value ) : void
$key string
$score mixed
$value string
return void

calculateRetryDelay() public method

Note: Calculations are done in microseconds.
public calculateRetryDelay ( integer $retry_iteration ) : integer
$retry_iteration integer
return integer

clearMultiValueIndex() public method

Clear all values from a set index
public clearMultiValueIndex ( string $key ) : void
$key string
return void

clearRefs() public method

Clear all refs from an entity (delete a ref list)
public clearRefs ( string $key ) : void
$key string
return void

clearSingleValueIndex() public method

Clear the value of a key-value index
public clearSingleValueIndex ( string $key ) : string
$key string
return string

clearSortedIndex() public method

Clear an entire sorted index
public clearSortedIndex ( string $key ) : void
$key string
return void

debugLog() public method

Create a debug log
public debugLog ( string $msg ) : void
$msg string
return void

delete() public method

Delete a primitive document
public delete ( string $key ) : void
$key string
return void

flush() public method

Execute the current unit of work
public flush ( ) : void
return void

getInitialRetryDelay() public method

Gets the Initial retry delay between failing $client commands.
public getInitialRetryDelay ( ) : integer
return integer

getMaxConnectionRetries() public method

Gets the Maximum number of Predis connection retries to occur if redis server doesn't respond.

getMultiValueIndex() public method

If the key does not exist, an empty array should be returned.
public getMultiValueIndex ( string $key ) : string[]
$key string
return string[]

getPreferredKeyScheme() public method

Get the drivers preferred key scheme
public getPreferredKeyScheme ( ) : Bravo3\Orm\KeySchemes\KeySchemeInterface
return Bravo3\Orm\KeySchemes\KeySchemeInterface

getRefs() public method

Get all refs to an entity
public getRefs ( string $key ) : Ref[]
$key string Entity ref key
return Bravo3\Orm\Drivers\Common\Ref[]

getRetryDelayCoefficient() public method

Returns the current retry delay coefficient set, which is the delay between each retry may happen if the requests to $client fails.

getScoreNormaliser() protected method

Lazy-loading score normaliser
protected getScoreNormaliser ( ) : ScoreNormaliser
return Bravo3\Orm\Services\ScoreNormaliser

getSingleValueIndex() public method

If the key does not exist, null should be returned.
public getSingleValueIndex ( string $key ) : string
$key string
return string

getSortedIndex() public method

If $start/$stop are null then they are assumed to be the start/end of the entire set
public getSortedIndex ( string $key, boolean $reverse = false, integer $start = null, integer $stop = null ) : string[]
$key string
$reverse boolean
$start integer
$stop integer
return string[]

getSortedIndexSize() public method

Get the size of a sorted index, without any filters applied
public getSortedIndexSize ( string $key ) : integer
$key string
return integer

isPubSubSupported() public method

Checks if the driver supports publish/subscribe pattern.
public isPubSubSupported ( ) : boolean
return boolean

listenToPubSub() public method

Add a callback to a particular subscription channel.
public listenToPubSub ( callable $callback ) : void
$callback callable
return void

persist() public method

Persist some primitive data
public persist ( string $key, SerialisedData $data, integer $ttl = null ) : void
$key string
$data Bravo3\Orm\Drivers\Common\SerialisedData
$ttl integer
return void

publishMessage() public method

Uses Redis PubSub implementation to push messages to the channel specified.
public publishMessage ( string $channel, string $message ) : integer
$channel string
$message string
return integer

purge() public method

Purge the current unit of work, clearing any unexecuted commands
public purge ( ) : void
return void

removeMultiValueIndex() public method

Remove one or more values from a set index
public removeMultiValueIndex ( string $key, string | array $value ) : void
$key string
$value string | array
return void

removeRef() public method

If the reference does not exist, no action is taken.
public removeRef ( string $key, Ref $ref ) : void
$key string Entity ref key
$ref Bravo3\Orm\Drivers\Common\Ref Reference to remove
return void

removeSortedIndex() public method

Remove an item from a sorted index
public removeSortedIndex ( string $key, string $value ) : void
$key string
$value string
return void

retrieve() public method

Retrieve an object, throwing an exception if not found
public retrieve ( string $key ) : SerialisedData
$key string
return Bravo3\Orm\Drivers\Common\SerialisedData

scan() public method

Scan key-value indices and return the value of all matching keys
public scan ( string $key ) : string[]
$key string
return string[]

setInitialRetryDelay() public method

Sets the Initial retry delay between failing $client commands.
public setInitialRetryDelay ( integer $initial_retry_delay ) : self
$initial_retry_delay integer the initial retry delay
return self

setMaxConnectionRetries() public method

Sets the Maximum number of Predis connection retries to occur if redis server doesn't respond.
public setMaxConnectionRetries ( integer $max_connection_retries ) : self
$max_connection_retries integer the max connection retries
return self

setRetryDelayCoefficient() public method

Set retry delay between $client command retries.
public setRetryDelayCoefficient ( integer $delay_coefficient ) : RedisDriver
$delay_coefficient integer
return RedisDriver

setSingleValueIndex() public method

Set a key-value index
public setSingleValueIndex ( string $key, string $value ) : void
$key string
$value string
return void

Property Details

$client protected_oe property

protected Client,Predis $client
return Predis\Client

$initial_retry_delay protected_oe property

Initial retry delay between failing $client commands.
protected int $initial_retry_delay
return integer

$max_connection_retries protected_oe property

Maximum number of Predis connection retries to occur if redis server doesn't respond.
protected int $max_connection_retries
return integer

$retry_delay_coefficient protected_oe property

Get/Write commands that fails will be retried again upto $max_connection_retries times with delays between each retry.
protected int $retry_delay_coefficient
return integer

$score_normaliser protected_oe property

protected ScoreNormaliser,Bravo3\Orm\Services $score_normaliser
return Bravo3\Orm\Services\ScoreNormaliser

$unit_of_work protected_oe property

protected UnitOfWork,Bravo3\Orm\Drivers\Common $unit_of_work
return Bravo3\Orm\Drivers\Common\UnitOfWork