23use Psr\Log\LoggerAwareInterface;
24use Psr\Log\LoggerInterface;
57 private const AUTH_NO_ERROR = 200;
62 private const AUTH_ERROR_TEMPORARY = 201;
67 private const AUTH_ERROR_PERMANENT = 202;
101 $this->lastError =
null;
112 public function __call( $name, $arguments ) {
114 $lname = strtolower( $name );
116 ( $lname ===
'blpop' || $lname ===
'brpop' || $lname ===
'brpoplpush' )
117 && count( $arguments ) > 1
120 $timeout = end( $arguments );
122 $this->pool->resetTimeout( $this->conn, ( $timeout > 0 ? $timeout + 1 : $timeout ) );
125 return $this->tryCall( $name, $arguments );
136 private function tryCall( $method, $arguments ) {
137 $this->conn->clearLastError();
139 $res = $this->conn->$method( ...$arguments );
140 $authError = $this->checkAuthentication();
141 if ( $authError === self::AUTH_ERROR_TEMPORARY ) {
142 $res = $this->conn->$method( ...$arguments );
144 if ( $authError === self::AUTH_ERROR_PERMANENT ) {
145 throw new RedisException(
"Failure reauthenticating to Redis." );
149 $this->postCallCleanup();
163 public function scan( &$iterator, $pattern =
null, $count =
null ) {
164 return $this->tryCall(
'scan', [ &$iterator, $pattern, $count ] );
178 public function sScan( $key, &$iterator, $pattern =
null, $count =
null ) {
179 return $this->tryCall(
'sScan', [ $key, &$iterator, $pattern, $count ] );
193 public function hScan( $key, &$iterator, $pattern =
null, $count =
null ) {
194 return $this->tryCall(
'hScan', [ $key, &$iterator, $pattern, $count ] );
208 public function zScan( $key, &$iterator, $pattern =
null, $count =
null ) {
209 return $this->tryCall(
'zScan', [ $key, &$iterator, $pattern, $count ] );
217 private function checkAuthentication() {
220 if ( !$this->pool->reauthenticateConnection( $this->server, $this->conn ) ) {
221 return self::AUTH_ERROR_PERMANENT;
223 $this->conn->clearLastError();
225 "Used automatic re-authentication for Redis.",
226 [
'redis_server' => $this->server ]
228 return self::AUTH_ERROR_TEMPORARY;
230 return self::AUTH_NO_ERROR;
238 private function postCallCleanup() {
242 $this->pool->resetTimeout( $this->conn );
253 $sha1 = sha1( $script );
258 $conn->clearLastError();
266 $this->pool->reauthenticateConnection(
$server,
$conn );
267 $conn->clearLastError();
270 "Used automatic re-authentication for Lua script '$sha1'.",
277 $conn->clearLastError();
280 "Used eval() for Lua script '$sha1'.",
287 $this->logger->error(
288 'Lua script error on server "{redis_server}": {lua_error}',
305 return $this->conn ===
$conn;
309 $this->pool->freeConnection( $this->server, $this->conn );
314class_alias( RedisConnRef::class,
'RedisConnRef' );
array $params
The job parameters.