PHP Redis Lua 脚本无法运行。

脚本在我的 MAC 上运行良好,phpinfo() 显示 PHP Redis 支持的版本为:Redis Version 2.2.5

我的 PHP 脚本是:

$script
    = "
        local count = redis.call('incr',KEYS[1])
        if tonumber(count) == 1 then
            redis.call('expire',KEYS[1],ARGV[1])
        end
        return count";

//$sha1_value = $this->conn->script('load', $script);
//var_dump($sha1_value);
if (FALSE === $this->conn->evalSha('e03b35e8ef29c5c746b1791ec7ae89e19f52156c', [
        $key,
        1800
    ], 1)
)
{
    $this->conn->eval($script, [
        $key,
        1800
    ], 1);
}

该脚本在我的服务器上无法运行,其 PHP Redis 版本为 2.1.0。

问题在于程序遇到 $this->conn->script()$this->conn->evalSha() 方法后会终止进程,这非常奇怪,因为没有错误日志被打印出来,当我使用 try ... catch ... 方法编写代码时,异常消息也没有被打印出来。

我查看了 Redis 的官方网站上的信息,它说:

EVAL and EVALSHA are used to evaluate scripts using the Lua interpreter built into Redis starting from version 2.6.0. ( http://redis.io/commands/EVAL)

所以我很好奇,因为我的服务器上的 redis-cli 版本已经是 2.8.0 了,而我的 MAC 上是 3.0.2。

那么我该如何找出问题?

点赞