| 1 | <?php |
||
| 23 | class PredisConnection extends LaravelPredisConnection |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * The number of times the client attempts to retry a command when it fails |
||
| 27 | * to connect to a Redis instance behind Sentinel. |
||
| 28 | * |
||
| 29 | * @var int |
||
| 30 | */ |
||
| 31 | protected $retryLimit = 20; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The time in milliseconds to wait before the client retries a failed |
||
| 35 | * command. |
||
| 36 | * |
||
| 37 | * @var int |
||
| 38 | */ |
||
| 39 | protected $retryWait = 1000; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Create a Redis Sentinel connection using a Predis client. |
||
| 43 | * |
||
| 44 | * @param Client $client The Redis client to wrap. |
||
| 45 | * @param array $sentinelOptions Sentinel-specific connection options. |
||
| 46 | */ |
||
| 47 | public function __construct(Client $client, array $sentinelOptions = [ ]) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Set the default amount of time to wait before determining that a |
||
| 62 | * connection attempt to a Sentinel server failed. |
||
| 63 | * |
||
| 64 | * @param float $seconds The timeout value in seconds. |
||
| 65 | * |
||
| 66 | * @return $this The current instance for method chaining. |
||
| 67 | */ |
||
| 68 | public function setSentinelTimeout($seconds) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Set the default number of attempts to retry a command when the client |
||
| 77 | * fails to connect to a Redis instance behind Sentinel. |
||
| 78 | * |
||
| 79 | * @param int $attempts With a value of 0, throw an exception after the |
||
| 80 | * first failed attempt. Pass a value of -1 to retry connections forever. |
||
| 81 | * |
||
| 82 | * @return $this The current instance for method chaining. |
||
| 83 | */ |
||
| 84 | public function setRetryLimit($attempts) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Set the time to wait before retrying a command after a connection |
||
| 94 | * attempt failed. |
||
| 95 | * |
||
| 96 | * @param int $milliseconds The wait time in milliseconds. When 0, retry |
||
| 97 | * a failed command immediately. |
||
| 98 | * |
||
| 99 | * @return $this The current instance for method chaining. |
||
| 100 | */ |
||
| 101 | public function setRetryWait($milliseconds) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Set whether the client should update the list of known Sentinels each |
||
| 111 | * time it needs to connect to a Redis server behind Sentinel. |
||
| 112 | * |
||
| 113 | * @param bool $enable If TRUE, fetch the updated Sentinel list. |
||
| 114 | * |
||
| 115 | * @return $this The current instance for method chaining. |
||
| 116 | */ |
||
| 117 | public function setUpdateSentinels($enable) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Execute commands in a transaction. |
||
| 126 | * |
||
| 127 | * This package overrides the transaction() method to work around a |
||
| 128 | * limitation in the Predis API that disallows transactions on "aggregate" |
||
| 129 | * connections like Sentinel. Note that transactions execute on the Redis |
||
| 130 | * master instance. |
||
| 131 | * |
||
| 132 | * @param callable $callback Contains the Redis commands to execute in the |
||
| 133 | * transaction. The callback receives a Predis\Transaction\MultiExec |
||
| 134 | * transaction abstraction as the only argument. We use this object to |
||
| 135 | * execute Redis commands by calling its methods just like we would with |
||
| 136 | * the Laravel Redis service. |
||
| 137 | * |
||
| 138 | * @return array|Predis\Transaction\MultiExec An array containing the |
||
| 139 | * result for each command executed during the transaction. If no callback |
||
| 140 | * provided, returns an instance of the Predis transaction abstraction. |
||
| 141 | */ |
||
| 142 | public function transaction(callable $callback = null) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Attempt to retry the provided operation when the client fails to connect |
||
| 151 | * to a Redis server. |
||
| 152 | * |
||
| 153 | * We adapt Predis' Sentinel connection failure handling logic here to |
||
| 154 | * reproduce the high-availability mode provided by the actual client. To |
||
| 155 | * work around "aggregate" connection limitations in Predis, this class |
||
| 156 | * provides methods that don't use the high-level Sentinel connection API |
||
| 157 | * of Predis directly, so it needs to handle connection failures itself. |
||
| 158 | * |
||
| 159 | * @param callable $callback The operation to execute. |
||
| 160 | * |
||
| 161 | * @return mixed The result of the first successful attempt. |
||
| 162 | */ |
||
| 163 | protected function retryOnFailure(callable $callback) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Get a Predis client instance for the master. |
||
| 185 | * |
||
| 186 | * @return Client The client instance for the current master. |
||
|
1 ignored issue
–
show
|
|||
| 187 | */ |
||
| 188 | protected function getMaster() |
||
| 192 | } |
||
| 193 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.