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() { ...@@ -54,9 +54,12 @@ function build_dates() {
static $dates = array(); static $dates = array();
if(!$dates) { if(!$dates) {
$r = new Redis; $r = new Redis;
$r->connect('localhost'); if($r->connect('localhost')) {
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); $r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$dates = $r->get('log:dates'); $dates = $r->get('log:dates');
} else {
$r = null;
}
if(!$dates) { if(!$dates) {
$res = DB::inst()->query('SELECT DISTINCT DATE("Time") FROM "Log" WHERE DATE("Time") > \'2000-01-01\' ORDER BY DATE("Time") DESC'); $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)) { while($row = pg_fetch_array($res)) {
...@@ -66,13 +69,15 @@ function build_dates() { ...@@ -66,13 +69,15 @@ function build_dates() {
$day = date('j', $time); $day = date('j', $time);
$dates[$year][$month][$day] = array($day, $row[0]); $dates[$year][$month][$day] = array($day, $row[0]);
} }
$ty = date('Y'); if($r) {
$tm = date('F'); $ty = date('Y');
$td = date('j'); $tm = date('F');
if(isset($dates[$ty][$tm][$td])) { $td = date('j');
$r->set('log:dates', $dates); if(isset($dates[$ty][$tm][$td])) {
$d = new DateTime('midnight tomorrow', new DateTimeZone('Pacific/Auckland')); $r->set('log:dates', $dates);
$r->expireAt('log:dates', $d->format('U')); $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