PHP Class Predis\Client

Author: Daniele Alessandri ([email protected])
Inheritance: implements predis\ClientInterface
Show file Open project: nrk/predis Class Usage Examples

Public Methods

Method Description
__call ( $commandID, $arguments )
__construct ( mixed $parameters = null, mixed $options = null )
connect ( ) Opens the underlying connection and connects to the server.
createCommand ( $commandID, $arguments = [] )
disconnect ( ) Closes the underlying connection and disconnects from the server.
executeCommand ( Predis\Command\CommandInterface $command )
executeRaw ( array $arguments, boolean &$error = null ) : mixed Executes a command without filtering its arguments, parsing the response, applying any prefix to keys or throwing exceptions on Redis errors even regardless of client options.
getClientBy ( string $selector, string $value, callable | null $callable = null ) : predis\ClientInterface | mixed Creates a new client from the specified .
getCommandFactory ( )
getConnection ( )
getIterator ( )
getOptions ( )
isConnected ( ) : boolean Returns the current state of the underlying connection.
monitor ( ) : Consumer Creates a new monitor consumer and returns it.
pipeline ( ) : Pipeline | array Creates a new pipeline context and returns it, or returns the results of a pipeline executed inside the optionally provided callable object.
pubSubLoop ( ) : Consumer | null Creates a new publish/subscribe context and returns it, or starts its loop inside the optionally provided callable object.
quit ( ) Closes the underlying connection and disconnects from the server.
transaction ( ) : MultiExec | array Creates a new transaction context and returns it, or returns the results of a transaction executed inside the optionally provided callable object.

Protected Methods

Method Description
createAggregateConnection ( mixed $parameters, string $option ) : Closure Creates an aggregate connection.
createConnection ( mixed $parameters ) : Predis\Connection\ConnectionInterface Creates single or aggregate connections from different types of arguments (string, array) or returns the passed argument if it is an instance of a class implementing Predis\Connection\ConnectionInterface.
createOptions ( mixed $options ) : Predis\Configuration\OptionsInterface Creates a new instance of Predis\Configuration\Options from different types of arguments or simply returns the passed argument if it is an instance of Predis\Configuration\OptionsInterface.
createPipeline ( array $options = null, mixed $callable = null ) : Pipeline | array Actual pipeline context initializer method.
createPubSub ( array $options = null, mixed $callable = null ) : Consumer | null Actual publish/subscribe context initializer method.
createTransaction ( array $options = null, mixed $callable = null ) : MultiExec | array Actual transaction context initializer method.
onErrorResponse ( Predis\Command\CommandInterface $command, Predis\Response\ErrorInterface $response ) : mixed Handles -ERR responses returned by Redis.

Private Methods

Method Description
sharedContextFactory ( string $initializer, array $argv = null ) : mixed Executes the specified initializer method on $this by adjusting the actual invokation depending on the arity (0, 1 or 2 arguments). This is simply an utility method to create Redis contexts instances since they follow a common initialization path.

Method Details

__call() public method

public __call ( $commandID, $arguments )

__construct() public method

public __construct ( mixed $parameters = null, mixed $options = null )
$parameters mixed Connection parameters for one or more servers.
$options mixed Options to configure some behaviours of the client.

connect() public method

Opens the underlying connection and connects to the server.
public connect ( )

createAggregateConnection() protected method

Creates an aggregate connection.
protected createAggregateConnection ( mixed $parameters, string $option ) : Closure
$parameters mixed Connection parameters.
$option string Option for aggregate connections (`aggregate`, `cluster`, `replication`).
return Closure

createCommand() public method

public createCommand ( $commandID, $arguments = [] )

createConnection() protected method

Accepted types for connection parameters are: - Instance of Predis\Connection\ConnectionInterface. - Instance of Predis\Connection\ParametersInterface. - Array - String - Callable
protected createConnection ( mixed $parameters ) : Predis\Connection\ConnectionInterface
$parameters mixed Connection parameters or connection instance.
return Predis\Connection\ConnectionInterface

createOptions() protected method

Creates a new instance of Predis\Configuration\Options from different types of arguments or simply returns the passed argument if it is an instance of Predis\Configuration\OptionsInterface.
protected createOptions ( mixed $options ) : Predis\Configuration\OptionsInterface
$options mixed Client options.
return Predis\Configuration\OptionsInterface

createPipeline() protected method

Actual pipeline context initializer method.
protected createPipeline ( array $options = null, mixed $callable = null ) : Pipeline | array
$options array Options for the context.
$callable mixed Optional callable used to execute the context.
return Predis\Pipeline\Pipeline | array

createPubSub() protected method

Actual publish/subscribe context initializer method.
protected createPubSub ( array $options = null, mixed $callable = null ) : Consumer | null
$options array Options for the context.
$callable mixed Optional callable used to execute the context.
return Predis\PubSub\Consumer | null

createTransaction() protected method

Actual transaction context initializer method.
protected createTransaction ( array $options = null, mixed $callable = null ) : MultiExec | array
$options array Options for the context.
$callable mixed Optional callable used to execute the context.
return Predis\Transaction\MultiExec | array

disconnect() public method

Closes the underlying connection and disconnects from the server.
public disconnect ( )

executeCommand() public method

public executeCommand ( Predis\Command\CommandInterface $command )
$command Predis\Command\CommandInterface

executeRaw() public method

It is possible to identify Redis error responses from normal responses using the second optional argument which is populated by reference.
public executeRaw ( array $arguments, boolean &$error = null ) : mixed
$arguments array Command arguments as defined by the command signature.
$error boolean Set to TRUE when Redis returned an error response.
return mixed

getClientBy() public method

The new client instances inherites the same options of the original one. When no callable object is supplied, this method returns the new client. When a callable object is supplied, the new client is passed as its sole argument and its return value is returned by this method to the caller. NOTE: This method works against any kind of underlying connection object as it uses a duck-typing approach and looks for a suitable method that matches the selector type to extract the correct connection.
public getClientBy ( string $selector, string $value, callable | null $callable = null ) : predis\ClientInterface | mixed
$selector string Type of selector (`id`, `key`, `slot`, `command`)
$value string Values of selector.
$callable callable | null Optional callable object.
return predis\ClientInterface | mixed

getCommandFactory() public method

public getCommandFactory ( )

getConnection() public method

public getConnection ( )

getIterator() public method

public getIterator ( )

getOptions() public method

public getOptions ( )

isConnected() public method

Returns the current state of the underlying connection.
public isConnected ( ) : boolean
return boolean

monitor() public method

Creates a new monitor consumer and returns it.
public monitor ( ) : Consumer
return Predis\Monitor\Consumer

onErrorResponse() protected method

Handles -ERR responses returned by Redis.
protected onErrorResponse ( Predis\Command\CommandInterface $command, Predis\Response\ErrorInterface $response ) : mixed
$command Predis\Command\CommandInterface Redis command that generated the error.
$response Predis\Response\ErrorInterface Instance of the error response.
return mixed

pipeline() public method

Creates a new pipeline context and returns it, or returns the results of a pipeline executed inside the optionally provided callable object.
public pipeline ( ) : Pipeline | array
return Predis\Pipeline\Pipeline | array

pubSubLoop() public method

Creates a new publish/subscribe context and returns it, or starts its loop inside the optionally provided callable object.
public pubSubLoop ( ) : Consumer | null
return Predis\PubSub\Consumer | null

quit() public method

This is the same as Client::disconnect() as it does not actually send the QUIT command to Redis, but simply closes the connection.
public quit ( )

transaction() public method

Creates a new transaction context and returns it, or returns the results of a transaction executed inside the optionally provided callable object.
public transaction ( ) : MultiExec | array
return Predis\Transaction\MultiExec | array