Created
October 8, 2011 16:36
-
-
Save yorktsai/1272511 to your computer and use it in GitHub Desktop.
PHP Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
while($row = $result->fetch_assoc()) { | |
STReservationHelper::peopleSumReducer($summary[STReservationHelper::CACHE_PEOPLE_SUM], $row); | |
// Other reducers ... | |
} | |
// set values | |
$redis->incrby(STReservationHelper::CACHE_PEOPLE_SUM, $summary[STReservationHelper::CACHE_PEOPLE_SUM]); | |
// set other summaries | |
// set last update | |
$redis->set(STReservationHelper::CACHE_LAST_UPDATE_TIMESTAMP, $endDateTime->getTimestamp()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add to cache | |
foreach($reservations as $reservation) { | |
$datetime = new DateTime($reservation[CC::CDATE]); | |
$redis->zadd($cacheKey, $datetime->getTimestamp(), json_encode($reservation)); | |
} | |
// remove until MAX_PUBLIOC_RESERVATIONS | |
$cachedReservations = $redis->zrevrangebyscore($cacheKey, 4102416000, 0, array('limit'=>array(self::CACHE_MAX_PUBLIC_RESERVATIONS, 1))); | |
if(count($cachedReservations) > 0) { | |
$reservation = json_decode($cachedReservations[0], true); | |
$startDateTime = new DateTime($reservation[CC::CDATE]); | |
$redis->zremrangebyscore($cacheKey, 0, $startDateTime->getTimestamp()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment