Skip to content

Instantly share code, notes, and snippets.

@yorktsai
Created October 8, 2011 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorktsai/1272511 to your computer and use it in GitHub Desktop.
Save yorktsai/1272511 to your computer and use it in GitHub Desktop.
PHP Redis
<?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());
<?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