Completed
Branch 2.x (b1c655)
by Julián
07:53
created

Redis   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 80
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 6 1
A close() 0 4 1
A read() 0 6 1
A write() 0 7 1
A destroy() 0 6 1
A gc() 0 4 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
namespace Jgut\Middleware\Sessionware\Handler;
13
14
/**
15
 * Redis session handler.
16
 */
17
class Redis implements Handler
18
{
19
    use HandlerTrait;
20
21
    /**
22
     * @var \Redis
23
     */
24
    protected $driver;
25
26
    /**
27
     * Redis session handler constructor.
28
     *
29
     * @param \Redis $driver
30
     */
31
    public function __construct(\Redis $driver)
32
    {
33
        $this->driver = $driver;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @throws \RuntimeException
40
     */
41
    public function open($savePath, $sessionName)
42
    {
43
        $this->testConfiguration();
44
45
        return true;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function close()
52
    {
53
        return true;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function read($sessionId)
60
    {
61
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
62
63
        return $this->driver->get($sessionId);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function write($sessionId, $sessionData)
70
    {
71
        $this->driver->set($sessionId, $sessionData);
72
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
73
74
        return true;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function destroy($sessionId)
81
    {
82
        $this->driver->del($sessionId);
83
84
        return true;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     *
90
     * @SuppressWarnings(PMD.ShortMethodName)
91
     */
92
    public function gc($maxLifetime)
93
    {
94
        return true;
95
    }
96
}
97