IndexClassesCommandsConfiguration

Configuration

Predis configuration is defined by ...Option classes under Configuration namespace.

cluster

Sets up an aggregate connection for multiple Redis instances, possibly with different profiles (versions) and other properties.

Accepted values:

Default value: predis-cluster.

Returns: a ClusterInterface.

Clustering description TODO.

new Predis([], ['cluster' => 'redis']);

connections

Configures actual underlying connection(s) used by Predis to run the commands. Also used in clustering.

Accepted values:

If an array is used and parameters option is defined, it's set as default parameters for the pool.

An initializer must be a string class name implementing NodeConnectionInterface ora callable (lazily invoked when it's time to initialize a scheme) returning such a class name.

Default value: a Connection\Factory with default set of schemes and initializers (below).

Returns: a Connection\FactoryInterface.

new Predis([], ['connections' => [
  'unix' => 'Predis\\Connection\\PhpiredisSocketConnection',
]]);

Standard schemes

Common parameters for all schemes:

tcp

StreamConnection (default)

Parameters:

Parameters common to tcp and unix schemes:

PhpiredisStreamConnection

Supports the same parameters as StreamConnection.

PhpiredisSocketConnection

Parameters common to tcp and unix schemes (see their descriptions in StreamSocket parameters above):

unix

StreamConnection (default)

Parameters:

See also common parameters in tcp.

PhpiredisStreamConnection

Supports the same parameters as StreamConnection.

PhpiredisSocketConnection

See also common parameters in tcp.

tls

StreamConnection (default)

Parameters are the same as of tcp, plus:

new Predis(['tls' => ['ssl' => ['verify_peer' => false]]]);
PhpiredisStreamConnection

Supports the same parameters as StreamConnection.

redis

Alias of tcp.

rediss

Alias of tls.

http

WebdisConnection (default)

Parameters:

parameters

Accepted values:

Default value: taken from private Parameters::$defaults, which are:

Returns: raw string or array as given by the user, or null.

See the connections option and the Connection\Parameters class for format details.

exceptions

Specifies what to do if a Redis command fails (also affects pipelines and transactions).

Accepted values:

Default value: boolean true.

Returns: boolean.

$predis = new Predis([], ['exceptions' => false]);
$predis->set('s', 'v');
$res = $predis->lpush('s', 'fail!');

echo get_class($res);
  //=> Predis\Response\Error

echo $res->getErrorType();
  //=> WRONGTYPE

echo $res->getMessage();
  //=> WRONGTYPE Operation against a key holding the wrong kind of value

prefix

Transforms key names referenced by Predis commands.

Accepted values:

Default value: none (no prefixing).

Returns: null or a ProcessorInterface.

KeyPrefixProcessor works by prepending the prefix to all key references that it recognizes using a built-in command list except for commands that implement PrefixableCommandInterface - for them, their prefixKeys() method is called with the current prefix string.

Example of simple key prefixing using standard command list:

$predis = new Predis([], ['prefix' => 'user118:']);
$predis->get('skey');
  // reads 'user118:skey' key.

Customizing command list

KeyPrefixProcessor doesn't recognize custom commands or scripts registered on the main Client object. Use setCommandHandler() method to register custom prefixers or unregister default ones.

Callback is given a CommandInterface and the prefix string. Its return value is ignored. Callback can be any valid callable including a string (MyClass::foo) or array reference.

If setCommandHandler is called without or with a null callback, that handler is unregistered (command's keys not transformed).

Note: callbacks are never called for commands implementing PrefixableCommandInterface.

Example of custom prefixing:

$pf = new Command\Processor\KeyPrefixProcessor('user118:');

// setPrefix() can be used to dynamically change the prefix.
$pf->setPrefix('user220:');

echo $pf->getPrefix();
  //=> string(8) "user220:"

// Register a custom handler for 'mycustomcmd':
$pf->setCommandHandler('mycustomcmd', function (CommandInterface $cmd, $prefix) {
  $a = $cmd->getArguments();
  $a[0] = $prefix.$a[0];
  $cmd->setRawArguments($a);
});

//$predis->mycustomcmd('key');
// Now the above will refer to 'user220:key'.

// Unregister a standard handler for 'sort':
$pf->setCommandHandler('sort');

// The same:
$pf->setCommandHandler('sort', null);

profile

Sets a "server profile" - info about Redis server that Predis is going to talk to, such as its version.

Accepted values:

Default value: Profile\Factory::getDefault().

Returns: ProfileInterface.

new Predis([], ['profile' => '2.6']);

new Predis([], ['profile' => 'dev']);
// or
new Predis([], ['profile' => Profile\Factory::getDevelopment()]);

Supported commands

2.0

APPEND AUTH BGREWRITEAOF BGSAVE BLPOP BRPOP CONFIG DBSIZE DECR DECRBY DEL DISCARD ECHO EXEC EXISTS EXPIRE EXPIREAT FLUSHALL FLUSHDB GET GETSET HDEL HEXISTS HGET HGETALL HINCRBY HKEYS HLEN HMGET HMSET HSET HSETNX HVALS INCR INCRBY INFO KEYS LASTSAVE LINDEX LLEN LPOP LPUSH LRANGE LREM LSET LTRIM MGET MONITOR MOVE MSET MSETNX MULTI PING PSUBSCRIBE PUBLISH PUNSUBSCRIBE QUIT RANDOMKEY RENAME RENAMENX RPOP RPOPLPUSH RPUSH SADD SAVE SCARD SDIFF SDIFFSTORE SELECT SET SETEX SETNX SHUTDOWN SINTER SINTERSTORE SISMEMBER SLAVEOF SMEMBERS SMOVE SORT SPOP SRANDMEMBER SREM SUBSCRIBE SUBSTR SUNION SUNIONSTORE TTL TYPE UNSUBSCRIBE ZADD ZCARD ZCOUNT ZINCRBY ZINTERSTORE ZRANGE ZRANGEBYSCORE ZRANK ZREM ZREMRANGEBYRANK ZREMRANGEBYSCORE ZREVRANGE ZREVRANK ZSCORE ZUNIONSTORE

2.2

Added commands:

BRPOPLPUSH GETBIT GETRANGE LINSERT LPUSHX OBJECT PERSIST RPUSHX SETBIT SETRANGE SLOWLOG STRLEN UNWATCH WATCH ZREVRANGEBYSCORE

2.4

Added commands:

CLIENT

2.6

Added commands:

BITCOUNT BITOP DUMP EVAL EVALSHA HINCRBYFLOAT INCRBYFLOAT MIGRATE PEXPIRE PEXPIREAT PSETEX PTTL RESTORE SCRIPT SENTINEL TIME

2.8

Added commands:

BITPOS COMMAND HSCAN PFADD PFCOUNT PFMERGE PUBSUB SCAN SSCAN ZLEXCOUNT ZRANGEBYLEX ZREMRANGEBYLEX ZREVRANGEBYLEX ZSCAN

3.0

No new commands supported by this profile. See 2.8.

3.2

Added commands:

BITFIELD GEOADD GEODIST GEOHASH GEOPOS GEORADIUS GEORADIUSBYMEMBER HSTRLEN

replication

Sets up an aggregate connection pool for master/slave replication.

Accepted values:

Default value: if autodiscovery option is set, uses autodiscovery to configure itself.

Returns: MasterSlaveReplication or null.

$predis = new Predis([], ['replication' => 'sentinel']);
$predis->options->replication;
  // instance of SentinelReplication

autodiscovery

If enabled, attempts automatic configuration of the replication (unless it was explicitly disabled with replication option).

Accepted values: boolean.

Default value: false.

Returns: raw user input.

service

Used by SentinelReplication, if enabled with the replication option.

aggregate

If present, configures an aggregate connection pool for Client.

Accepted values:

Default value: null.

Returns: callable or null.