php redis set stand-alone lock (rpm)

If a request to update the cache of a long time, even more than the lock period is longer, resulting in cache update process, the lock fails, then another request acquires a lock, but the first time a request is updated in the cache , if the situation is not to be judged directly remove the lock, the lock will be created accidentally deleted other requests, so we need to introduce a random value in the creation of locks:

$ok = $redis->set($key, $random, array('nx', 'ex' =>5));

if ($ok) {
    $cache->update();

    if ($redis->get($key) == $random) {
        $redis->del($key);
    }
}

Guess you like

Origin www.cnblogs.com/sandea/p/11570516.html