Completed
Branch 2.x (03096d)
by Julián
08:36
created

Redis::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * sessionware (https://github.com/juliangut/sessionware).
5
 * PSR7 session management middleware.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/sessionware
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Jgut\Sessionware\Handler;
15
16
/**
17
 * Redis session handler.
18
 */
19
class Redis implements Handler
20
{
21
    use HandlerTrait;
22
23
    /**
24
     * @var \Redis
25
     */
26
    protected $driver;
27
28
    /**
29
     * Redis session handler constructor.
30
     *
31
     * @param \Redis $driver
32
     */
33
    public function __construct(\Redis $driver)
34
    {
35
        $this->driver = $driver;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws \RuntimeException
42
     *
43
     * @SuppressWarnings(PMD.UnusedFormalParameter)
44
     */
45
    public function open($savePath, $sessionName)
46
    {
47
        $this->testConfiguration();
48
49
        return true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function close()
56
    {
57
        return true;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function read($sessionId)
64
    {
65
        $sessionData = $this->driver->get($sessionId);
66
67
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
68
69
        return $sessionData;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function write($sessionId, $sessionData)
76
    {
77
        $this->driver->set($sessionId, $sessionData);
78
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
79
80
        return true;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function destroy($sessionId)
87
    {
88
        $this->driver->del($sessionId);
89
90
        return true;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     *
96
     * @SuppressWarnings(PMD.ShortMethodName)
97
     * @SuppressWarnings(PMD.UnusedFormalParameter)
98
     */
99
    public function gc($maxLifetime)
100
    {
101
        return true;
102
    }
103
}
104