RedisHandler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A destroy() 0 4 1
A read() 0 7 2
A write() 0 5 1
A gc() 0 4 1
A open() 0 4 1
A close() 0 4 1
1
<?php
2
namespace Wandu\Http\Session\Handler;
3
4
use Predis\Client;
5
use SessionHandlerInterface;
6
7
class RedisHandler implements SessionHandlerInterface
8
{
9
    /** @var \Predis\Client */
10
    private $client;
11
12
    /** @var int */
13
    private $expire;
14
15
    /**
16
     * @param \Predis\Client $client
17
     * @param int $expire
18
     */
19
    public function __construct(Client $client, $expire = 1800)
20
    {
21
        $this->client = $client;
22
        $this->expire = $expire;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function destroy($sessionId)
29
    {
30
        $this->client->del("wandu.http.sess.{$sessionId}");
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function read($sessionId)
37
    {
38
        if ($dataSet = $this->client->get("wandu.http.sess.{$sessionId}")) {
39
            return $dataSet;
40
        }
41
        return '';
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function write($sessionId, $dataSet)
48
    {
49
        $this->client->set("wandu.http.sess.{$sessionId}", $dataSet);
50
        $this->client->expire("wandu.http.sess.{$sessionId}", $this->expire);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function gc($maxlifetime)
57
    {
58
        return true;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function open($savePath, $sessionId)
65
    {
66
        return true;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function close()
73
    {
74
        return true;
75
    }
76
}
77