嘿伙计们!我正在对 Predis 进行乐观锁定。问题是 Redis 文档说,当被监视的键被修改时,执行返回一个“Null Multi-bulk reply”。它在 Predis 中看起来如何?可悲的是,我没有找到任何有用的 Pedis 文档(不包括非常基本的教程)。
这是我的代码目前的样子:
private function updateUrlMaxProcessingTime($time, $hoursSinceUnixEpoch) {
    //Save the key and the field. They can change anytime because of the timestamp.
    $key = $this->statisticsConfig->getKeyFromDataName(StatisticsEnum::URL_MAX_PROCESS_TIME, $hoursSinceUnixEpoch);
    $field = $this->statisticsConfig->getFieldFromDataName(StatisticsEnum::URL_MAX_PROCESS_TIME, $hoursSinceUnixEpoch);
    //Update the max url processing time if necessary.
    $this->redis->watch($key);
    $val = $this->redis->hget($key, $field);
    if ($val < $time) {
        $this->redis->multi();
        $this->redis->hset($key, $field, $time);
        $result = $this->redis->exec();
        //TODO: fix this
        if ($result != null && $result[0] != null && $result[0] != -1) {
            return true;
        } else {
            return false;
        }
    } else {
        $this->redis->unwatch();
        return true;
    }
}
只要它返回false,我就会调用该函数。