PHP 클래스 Predis\Connection\Cluster\RedisCluster

This connection backend offers smart support for redis-cluster by handling automatic slots map (re)generation upon -MOVED or -ASK responses returned by Redis when redirecting a client to a different node. The cluster can be pre-initialized using only a subset of the actual nodes in the cluster, Predis will do the rest by adjusting the slots map and creating the missing underlying connection instances on the fly. It is possible to pre-associate connections to a slots range with the "slots" parameter in the form "$first-$last". This can greatly reduce runtime node guessing and redirections. It is also possible to ask for the full and updated slots map directly to one of the nodes and optionally enable such a behaviour upon -MOVED redirections. Asking for the cluster configuration to Redis is actually done by issuing a CLUSTER SLOTS command to a random node in the pool.
저자: Daniele Alessandri ([email protected])
상속: implements ClusterInterface, implements IteratorAggregate, implements Countable
파일 보기 프로젝트 열기: nrk/predis

공개 메소드들

메소드 설명
__construct ( Predis\Connection\FactoryInterface $connections, Predis\Cluster\StrategyInterface $strategy = null )
add ( Predis\Connection\NodeConnectionInterface $connection )
askSlotMap ( Predis\Connection\NodeConnectionInterface $connection = null ) Generates an updated slots map fetching the cluster configuration using the CLUSTER SLOTS command against the specified node or a random one from the pool.
buildSlotMap ( ) Generates the current slots map by guessing the cluster configuration out of the connection parameters of the connections in the pool.
connect ( )
count ( )
disconnect ( )
executeCommand ( Predis\Command\CommandInterface $command )
getClusterStrategy ( ) : Predis\Cluster\StrategyInterface Returns the underlying command hash strategy used to hash commands by using keys found in their arguments.
getConnectionByCommand ( Predis\Command\CommandInterface $command )
getConnectionById ( $connectionID )
getConnectionBySlot ( integer $slot ) : Predis\Connection\NodeConnectionInterface Returns the connection currently associated to a given slot.
getConnectionFactory ( ) : Predis\Connection\FactoryInterface Returns the underlying connection factory used to create new connection instances to Redis nodes indicated by redis-cluster.
getIterator ( )
getSlotMap ( ) : SlotMap Returns the underlying slot map.
isConnected ( )
readResponse ( Predis\Command\CommandInterface $command )
remove ( Predis\Connection\NodeConnectionInterface $connection )
removeById ( string $connectionID ) : boolean Removes a connection instance by using its identifier.
setRetryLimit ( integer $retry ) Sets the maximum number of retries for commands upon server failure.
useClusterSlots ( boolean $value ) Enables automatic fetching of the current slots map from one of the nodes using the CLUSTER SLOTS command. This option is enabled by default as asking the current slots map to Redis upon -MOVED responses may reduce overhead by eliminating the trial-and-error nature of the node guessing procedure, mostly when targeting many keys that would end up in a lot of redirections.
writeRequest ( Predis\Command\CommandInterface $command )

보호된 메소드들

메소드 설명
createConnection ( string $connectionID ) : Predis\Connection\NodeConnectionInterface Creates a new connection instance from the given connection ID.
getRandomConnection ( ) : Predis\Connection\NodeConnectionInterface | null Returns a random connection from the pool.
guessNode ( integer $slot ) : string Guesses the correct node associated to a given slot using a precalculated slots map, falling back to the same logic used by Redis to initialize a cluster (best-effort).
move ( Predis\Connection\NodeConnectionInterface $connection, integer $slot ) Permanently associates the connection instance to a new slot.
onAskResponse ( Predis\Command\CommandInterface $command, string $details ) : mixed Handles -ASK responses by executing again the command against the node indicated by the Redis response.
onErrorResponse ( Predis\Command\CommandInterface $command, Predis\Response\ErrorInterface $error ) : mixed Handles -ERR responses returned by Redis.
onMovedResponse ( Predis\Command\CommandInterface $command, string $details ) : mixed Handles -MOVED responses by executing again the command against the node indicated by the Redis response.

비공개 메소드들

메소드 설명
queryClusterNodeForSlotMap ( Predis\Connection\NodeConnectionInterface $connection ) : mixed Queries the specified node of the cluster to fetch the updated slots map.
retryCommandOnFailure ( Predis\Command\CommandInterface $command, string $method ) : mixed Ensures that a command is executed one more time on connection failure.

메소드 상세

__construct() 공개 메소드

public __construct ( Predis\Connection\FactoryInterface $connections, Predis\Cluster\StrategyInterface $strategy = null )
$connections Predis\Connection\FactoryInterface Optional connection factory.
$strategy Predis\Cluster\StrategyInterface Optional cluster strategy.

add() 공개 메소드

public add ( Predis\Connection\NodeConnectionInterface $connection )
$connection Predis\Connection\NodeConnectionInterface

askSlotMap() 공개 메소드

Generates an updated slots map fetching the cluster configuration using the CLUSTER SLOTS command against the specified node or a random one from the pool.
public askSlotMap ( Predis\Connection\NodeConnectionInterface $connection = null )
$connection Predis\Connection\NodeConnectionInterface Optional connection instance.

buildSlotMap() 공개 메소드

Generation is based on the same algorithm used by Redis to generate the cluster, so it is most effective when all of the connections supplied on initialization have the "slots" parameter properly set accordingly to the current cluster configuration.
public buildSlotMap ( )

connect() 공개 메소드

public connect ( )

count() 공개 메소드

public count ( )

createConnection() 보호된 메소드

Creates a new connection instance from the given connection ID.
protected createConnection ( string $connectionID ) : Predis\Connection\NodeConnectionInterface
$connectionID string Identifier for the connection.
리턴 Predis\Connection\NodeConnectionInterface

disconnect() 공개 메소드

public disconnect ( )

executeCommand() 공개 메소드

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

getClusterStrategy() 공개 메소드

Returns the underlying command hash strategy used to hash commands by using keys found in their arguments.
public getClusterStrategy ( ) : Predis\Cluster\StrategyInterface
리턴 Predis\Cluster\StrategyInterface

getConnectionByCommand() 공개 메소드

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

getConnectionById() 공개 메소드

public getConnectionById ( $connectionID )

getConnectionBySlot() 공개 메소드

Returns the connection currently associated to a given slot.
public getConnectionBySlot ( integer $slot ) : Predis\Connection\NodeConnectionInterface
$slot integer Slot index.
리턴 Predis\Connection\NodeConnectionInterface

getConnectionFactory() 공개 메소드

Returns the underlying connection factory used to create new connection instances to Redis nodes indicated by redis-cluster.
public getConnectionFactory ( ) : Predis\Connection\FactoryInterface
리턴 Predis\Connection\FactoryInterface

getIterator() 공개 메소드

public getIterator ( )

getRandomConnection() 보호된 메소드

Returns a random connection from the pool.
protected getRandomConnection ( ) : Predis\Connection\NodeConnectionInterface | null
리턴 Predis\Connection\NodeConnectionInterface | null

getSlotMap() 공개 메소드

Returns the underlying slot map.
public getSlotMap ( ) : SlotMap
리턴 Predis\Cluster\SlotMap

guessNode() 보호된 메소드

Guesses the correct node associated to a given slot using a precalculated slots map, falling back to the same logic used by Redis to initialize a cluster (best-effort).
protected guessNode ( integer $slot ) : string
$slot integer Slot index.
리턴 string Connection ID.

isConnected() 공개 메소드

public isConnected ( )

move() 보호된 메소드

The connection is added to the connections pool if not yet included.
protected move ( Predis\Connection\NodeConnectionInterface $connection, integer $slot )
$connection Predis\Connection\NodeConnectionInterface Connection instance.
$slot integer Target slot index.

onAskResponse() 보호된 메소드

Handles -ASK responses by executing again the command against the node indicated by the Redis response.
protected onAskResponse ( Predis\Command\CommandInterface $command, string $details ) : mixed
$command Predis\Command\CommandInterface Command that generated the -ASK response.
$details string Parameters of the -ASK response.
리턴 mixed

onErrorResponse() 보호된 메소드

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

onMovedResponse() 보호된 메소드

Handles -MOVED responses by executing again the command against the node indicated by the Redis response.
protected onMovedResponse ( Predis\Command\CommandInterface $command, string $details ) : mixed
$command Predis\Command\CommandInterface Command that generated the -MOVED response.
$details string Parameters of the -MOVED response.
리턴 mixed

readResponse() 공개 메소드

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

remove() 공개 메소드

public remove ( Predis\Connection\NodeConnectionInterface $connection )
$connection Predis\Connection\NodeConnectionInterface

removeById() 공개 메소드

Removes a connection instance by using its identifier.
public removeById ( string $connectionID ) : boolean
$connectionID string Connection identifier.
리턴 boolean True if the connection was in the pool.

setRetryLimit() 공개 메소드

-1 = unlimited retry attempts 0 = no retry attempts (fails immediatly) n = fail only after n retry attempts
public setRetryLimit ( integer $retry )
$retry integer Number of retry attempts.

useClusterSlots() 공개 메소드

The slots map can still be manually fetched using the askSlotMap() method whether or not this option is enabled.
public useClusterSlots ( boolean $value )
$value boolean Enable or disable the use of CLUSTER SLOTS.

writeRequest() 공개 메소드

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