20use Psr\Log\LoggerInterface;
21use Psr\Log\LoggerAwareInterface;
77 $this->lastError =
null;
80 public function __call( $name, $arguments ) {
84 $lname = strtolower( $name );
85 if ( ( $lname ===
'blpop' || $lname ==
'brpop' )
86 && is_array( $arguments[0] ) && isset( $arguments[1] )
88 $this->pool->resetTimeout(
$conn, $arguments[1] + 1 );
89 } elseif ( $lname ===
'brpoplpush' && isset( $arguments[2] ) ) {
90 $this->pool->resetTimeout(
$conn, $arguments[2] + 1 );
93 $conn->clearLastError();
95 $res = call_user_func_array( [
$conn, $name ], $arguments );
96 if ( preg_match(
'/^ERR operation not permitted\b/',
$conn->getLastError() ) ) {
97 $this->pool->reauthenticateConnection( $this->server,
$conn );
98 $conn->clearLastError();
99 $res = call_user_func_array( [
$conn, $name ], $arguments );
101 "Used automatic re-authentication for method '$name'.",
102 [
'redis_server' => $this->server ]
105 }
catch ( RedisException
$e ) {
106 $this->pool->resetTimeout(
$conn );
112 $this->pool->resetTimeout(
$conn );
125 $sha1 = sha1( $script );
130 $conn->clearLastError();
136 if ( preg_match(
'/^ERR operation not permitted\b/',
$conn->getLastError() ) ) {
137 $this->pool->reauthenticateConnection(
$server,
$conn );
138 $conn->clearLastError();
141 "Used automatic re-authentication for Lua script '$sha1'.",
146 if ( preg_match(
'/^NOSCRIPT/',
$conn->getLastError() ) ) {
147 $conn->clearLastError();
150 "Used eval() for Lua script '$sha1'.",
155 if (
$conn->getLastError() ) {
156 $this->logger->error(
157 'Lua script error on server "{redis_server}": {lua_error}',
160 'lua_error' =>
$conn->getLastError()
175 return $this->conn ===
$conn;
179 $this->pool->freeConnection( $this->server, $this->conn );
Helper class to handle automatically marking connectons as reusable (via RAII pattern)
RedisConnectionPool $pool
__call( $name, $arguments)
luaEval( $script, array $params, $numKeys)
__construct(RedisConnectionPool $pool, $server, Redis $conn, LoggerInterface $logger)
setLogger(LoggerInterface $logger)
isConnIdentical(Redis $conn)
Helper class to manage Redis connections.
returning false will NOT prevent logging $e