Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LggrCacheRedis
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 __destruct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 store
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 retrieve
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 purge
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Lggr;
3
4/**
5 * @brief Caching class for redis based cache.
6 */
7class LggrCacheRedis extends AbstractLggrCache {
8
9    // 5 minutes
10    const MAXAGE = 300;
11
12    const REDISHOST = 'redis';
13
14    const REDISDB = 0;
15
16    const REDISPFX = 'lggr_';
17
18    private $r = null;
19
20    function __construct() {
21        $this->r = new \Redis();
22        $this->r->connect(self::REDISHOST);
23        $this->r->select(self::REDISDB);
24    }
25
26    // constructor
27    function __destruct() {
28        $this->r->close();
29    }
30
31    // destructor
32    public function store($key, $value) {
33        $s = serialize($value);
34        $this->r->setex(SELF::REDISPFX . $key, self::MAXAGE, $s);
35    }
36
37    // function
38    public function retrieve($key) {
39        $value = $this->r->get(SELF::REDISPFX . $key);
40        if (false === $value) {
41            return null;
42        }
43        return unserialize($value);
44    }
45
46    // function
47    public function purge($key) {
48        $this->r->delete(SELF::REDISPFX . $key);
49    } // function
50} // class