Commit 7a73e914 authored by Simon Welsh's avatar Simon Welsh

Handle redis not working

git-svn-id: svn+ssh://lsgn/var/logbot-www@61 5f99df0c-6b0a-442a-b40a-040688e84a9d
parent a1beb9ee
......@@ -54,9 +54,12 @@ function build_dates() {
static $dates = array();
if(!$dates) {
$r = new Redis;
$r->connect('localhost');
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$dates = $r->get('log:dates');
if($r->connect('localhost')) {
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$dates = $r->get('log:dates');
} else {
$r = null;
}
if(!$dates) {
$res = DB::inst()->query('SELECT DISTINCT DATE("Time") FROM "Log" WHERE DATE("Time") > \'2000-01-01\' ORDER BY DATE("Time") DESC');
while($row = pg_fetch_array($res)) {
......@@ -66,13 +69,15 @@ function build_dates() {
$day = date('j', $time);
$dates[$year][$month][$day] = array($day, $row[0]);
}
$ty = date('Y');
$tm = date('F');
$td = date('j');
if(isset($dates[$ty][$tm][$td])) {
$r->set('log:dates', $dates);
$d = new DateTime('midnight tomorrow', new DateTimeZone('Pacific/Auckland'));
$r->expireAt('log:dates', $d->format('U'));
if($r) {
$ty = date('Y');
$tm = date('F');
$td = date('j');
if(isset($dates[$ty][$tm][$td])) {
$r->set('log:dates', $dates);
$d = new DateTime('midnight tomorrow', new DateTimeZone('Pacific/Auckland'));
$r->expireAt('log:dates', $d->format('U'));
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment