Client
in package
implements
ClientInterface, IteratorAggregate
Client class used for connecting and executing commands on Redis.
This is the main high-level abstraction of Predis upon which various other abstractions are built. Internally it aggregates various other classes each one with its own responsibility and scope.
Tags
Interfaces, Classes, Traits and Enums
- ClientInterface
- Interface defining a client able to execute commands against Redis.
- IteratorAggregate
Table of Contents
- VERSION = '1.1.1'
- $connection : mixed
- $options : mixed
- $profile : mixed
- __call() : mixed
- Creates a Redis command with the specified arguments and sends a request to the server.
- __construct() : mixed
- connect() : mixed
- Opens the underlying connection and connects to the server.
- createCommand() : CommandInterface
- Creates a new instance of the specified Redis command.
- disconnect() : mixed
- Closes the underlying connection and disconnects from the server.
- executeCommand() : mixed
- Executes the specified Redis command.
- executeRaw() : 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.
- getClientFor() : Client
- Creates a new client instance for the specified connection ID or alias, only when working with an aggregate connection (cluster, replication).
- getConnection() : ConnectionInterface
- Returns the underlying connection instance.
- getConnectionById() : NodeConnectionInterface
- Retrieves the specified connection from the aggregate connection when the client is in cluster or replication mode.
- getIterator() : mixed
- {@inheritdoc}
- getOptions() : OptionsInterface
- Returns the client options specified upon initialization.
- getProfile() : ProfileInterface
- Returns the server profile used by the client.
- isConnected() : bool
- Returns the current state of the underlying connection.
- monitor() : Consumer
- Creates a new monitor consumer and returns it.
- pipeline() : Pipeline|array<string|int, mixed>
- 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() : mixed
- Closes the underlying connection and disconnects from the server.
- transaction() : MultiExec|array<string|int, mixed>
- Creates a new transaction context and returns it, or returns the results of a transaction executed inside the optionally provided callable object.
- createConnection() : 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() : 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() : Pipeline|array<string|int, mixed>
- Actual pipeline context initializer method.
- createPubSub() : Consumer|null
- Actual publish/subscribe context initializer method.
- createTransaction() : MultiExec|array<string|int, mixed>
- Actual transaction context initializer method.
- getConnectionInitializerWrapper() : Closure
- Wraps a callable to make sure that its returned value represents a valid connection type.
- onErrorResponse() : mixed
- Handles -ERR responses returned by Redis.
- sharedContextFactory() : 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.
Constants
VERSION
public
mixed
VERSION
= '1.1.1'
Properties
$connection
protected
mixed
$connection
$options
protected
mixed
$options
$profile
private
mixed
$profile
Methods
__call()
Creates a Redis command with the specified arguments and sends a request to the server.
public
__call(mixed $commandID, mixed $arguments) : mixed
Parameters
- $commandID : mixed
- $arguments : mixed
-
Arguments for the command.
Return values
mixed —__construct()
public
__construct([mixed $parameters = null ][, mixed $options = null ]) : mixed
Parameters
- $parameters : mixed = null
-
Connection parameters for one or more servers.
- $options : mixed = null
-
Options to configure some behaviours of the client.
Return values
mixed —connect()
Opens the underlying connection and connects to the server.
public
connect() : mixed
Return values
mixed —createCommand()
Creates a new instance of the specified Redis command.
public
createCommand(mixed $commandID[, mixed $arguments = array() ]) : CommandInterface
Parameters
- $commandID : mixed
- $arguments : mixed = array()
-
Arguments for the command.
Return values
CommandInterface —disconnect()
Closes the underlying connection and disconnects from the server.
public
disconnect() : mixed
Return values
mixed —executeCommand()
Executes the specified Redis command.
public
executeCommand(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
-
Command instance.
Return values
mixed —executeRaw()
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.
public
executeRaw(array<string|int, mixed> $arguments[, bool &$error = null ]) : mixed
It is possible to identify Redis error responses from normal responses using the second optional argument which is populated by reference.
Parameters
- $arguments : array<string|int, mixed>
-
Command arguments as defined by the command signature.
- $error : bool = null
-
Set to TRUE when Redis returned an error response.
Return values
mixed —getClientFor()
Creates a new client instance for the specified connection ID or alias, only when working with an aggregate connection (cluster, replication).
public
getClientFor(string $connectionID) : Client
The new client instances uses the same options of the original one.
Parameters
- $connectionID : string
-
Identifier of a connection.
Tags
Return values
Client —getConnection()
Returns the underlying connection instance.
public
getConnection() : ConnectionInterface
Return values
ConnectionInterface —getConnectionById()
Retrieves the specified connection from the aggregate connection when the client is in cluster or replication mode.
public
getConnectionById(string $connectionID) : NodeConnectionInterface
Parameters
- $connectionID : string
-
Index or alias of the single connection.
Tags
Return values
NodeConnectionInterface —getIterator()
{@inheritdoc}
public
getIterator() : mixed
Return values
mixed —getOptions()
Returns the client options specified upon initialization.
public
getOptions() : OptionsInterface
Return values
OptionsInterface —getProfile()
Returns the server profile used by the client.
public
getProfile() : ProfileInterface
Return values
ProfileInterface —isConnected()
Returns the current state of the underlying connection.
public
isConnected() : bool
Return values
bool —monitor()
Creates a new monitor consumer and returns it.
public
monitor() : Consumer
Return values
Consumer —pipeline()
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<string|int, mixed>
Return values
Pipeline|array<string|int, mixed> —pubSubLoop()
Creates a new publish/subscribe context and returns it, or starts its loop inside the optionally provided callable object.
public
pubSubLoop() : Consumer|null
Return values
Consumer|null —quit()
Closes the underlying connection and disconnects from the server.
public
quit() : mixed
This is the same as Client::disconnect()
as it does not actually send
the QUIT
command to Redis, but simply closes the connection.
Return values
mixed —transaction()
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<string|int, mixed>
Return values
MultiExec|array<string|int, mixed> —createConnection()
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.
protected
createConnection(mixed $parameters) : ConnectionInterface
Accepted types for connection parameters are:
- Instance of Predis\Connection\ConnectionInterface.
- Instance of Predis\Connection\ParametersInterface.
- Array
- String
- Callable
Parameters
- $parameters : mixed
-
Connection parameters or connection instance.
Tags
Return values
ConnectionInterface —createOptions()
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) : OptionsInterface
Parameters
- $options : mixed
-
Client options.
Tags
Return values
OptionsInterface —createPipeline()
Actual pipeline context initializer method.
protected
createPipeline([array<string|int, mixed> $options = null ][, mixed $callable = null ]) : Pipeline|array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = null
-
Options for the context.
- $callable : mixed = null
-
Optional callable used to execute the context.
Return values
Pipeline|array<string|int, mixed> —createPubSub()
Actual publish/subscribe context initializer method.
protected
createPubSub([array<string|int, mixed> $options = null ][, mixed $callable = null ]) : Consumer|null
Parameters
- $options : array<string|int, mixed> = null
-
Options for the context.
- $callable : mixed = null
-
Optional callable used to execute the context.
Return values
Consumer|null —createTransaction()
Actual transaction context initializer method.
protected
createTransaction([array<string|int, mixed> $options = null ][, mixed $callable = null ]) : MultiExec|array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = null
-
Options for the context.
- $callable : mixed = null
-
Optional callable used to execute the context.
Return values
MultiExec|array<string|int, mixed> —getConnectionInitializerWrapper()
Wraps a callable to make sure that its returned value represents a valid connection type.
protected
getConnectionInitializerWrapper(mixed $callable) : Closure
Parameters
- $callable : mixed
Return values
Closure —onErrorResponse()
Handles -ERR responses returned by Redis.
protected
onErrorResponse(CommandInterface $command, ErrorInterface $response) : mixed
Parameters
- $command : CommandInterface
-
Redis command that generated the error.
- $response : ErrorInterface
-
Instance of the error response.
Tags
Return values
mixed —sharedContextFactory()
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.
private
sharedContextFactory(string $initializer[, array<string|int, mixed> $argv = null ]) : mixed
Parameters
- $initializer : string
-
Method name.
- $argv : array<string|int, mixed> = null
-
Arguments for the method.