RedisHandler::read()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
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