Exemple #1
0
 /**
  * @param string $script
  * @param array $params
  * @param int $numKeys
  * @return mixed
  * @throws RedisException
  */
 public function luaEval($script, array $params, $numKeys)
 {
     $sha1 = sha1($script);
     // 40 char hex
     $conn = $this->conn;
     // convenience
     $server = $this->server;
     // convenience
     // Try to run the server-side cached copy of the script
     $conn->clearLastError();
     $res = $conn->evalSha($sha1, $params, $numKeys);
     // If we got a permission error reply that means that (a) we are not in
     // multi()/pipeline() and (b) some connection problem likely occurred. If
     // the password the client gave was just wrong, an exception should have
     // been thrown back in getConnection() previously.
     if (preg_match('/^ERR operation not permitted\\b/', $conn->getLastError())) {
         $this->pool->reauthenticateConnection($server, $conn);
         $conn->clearLastError();
         $res = $conn->eval($script, $params, $numKeys);
         $this->logger->info("Used automatic re-authentication for Lua script '{$sha1}'.", ['redis_server' => $server]);
     }
     // If the script is not in cache, use eval() to retry and cache it
     if (preg_match('/^NOSCRIPT/', $conn->getLastError())) {
         $conn->clearLastError();
         $res = $conn->eval($script, $params, $numKeys);
         $this->logger->info("Used eval() for Lua script '{$sha1}'.", ['redis_server' => $server]);
     }
     if ($conn->getLastError()) {
         // script bug?
         $this->logger->error('Lua script error on server "{redis_server}": {lua_error}', ['redis_server' => $server, 'lua_error' => $conn->getLastError()]);
     }
     $this->lastError = $conn->getLastError() ?: $this->lastError;
     return $res;
 }