HuyPV
Saturday, December 22, 2012
$nbTry = 0;
$success = false;
do {
$redis->watch($cacheKey);
$val = $redis->get($cacheKey);
if ($val === false) {
// No cached data in Redis
// load refresh data from DB and cache it
return false;
}
$result = $redis->multi()
->set($cacheKey, $newVal)
->exec();
if ($result !== false) {
// add your code here: update DB, clean cache
break;
} else {
usleep(10);
$nbTry++;
if ($nbTry >= 1500000) break; //timeout 15 sec
}
} while (true);
return $success;
Title:
Implement lock with redis
Description:
$nbTry = 0; $success = false; do { $redis->watch($cacheKey); $val = $redis->get($cacheKey); if ($val === false) { // No ...
...
Rating:
4