-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRedisCacheAdapter.php
More file actions
76 lines (65 loc) · 1.71 KB
/
RedisCacheAdapter.php
File metadata and controls
76 lines (65 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of the "EloGank League of Legends Replay Observer" package.
*
* https://github.com/EloGank/lol-replay-observer
*
* For the full license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NEloGank\Replay\Observer\Cache\Adapter;
/**
* @author Sylvain Lorinet <sylvain.lorinet@gmail.com>
*/
class RedisCacheAdapter implements CacheAdapterInterface
{
/**
* @var mixed
*/
protected $redis;
/**
* @param mixed $redis
*/
public function __construct($redis)
{
$this->redis = $redis;
}
/**
* @param string $key The cache key
*
* @return bool True if the key exists and is not expired
*/
public function has($key)
{
return $this->redis->exists($key);
}
/**
* @param string $key The cache key
*
* @return mixed The value for the selected key
*/
public function get($key)
{
return $this->redis->get($key);
}
/**
* @param string $key The cache key
* @param mixed $value The value
* @param null|int $ttl The time to live in second, must be greater than zero. Let NULL if no expiration.
*
* @return bool
*/
public function set($key, $value, $ttl = null)
{
if (null == $ttl) {
return $this->redis->set($key, $value);
}
if (null == $ttl) {
return $this->redis->set($key, $value);
}
if (!is_int($ttl) || 0 >= $ttl) {
throw new \InvalidArgumentException('The time to live parameter must be an integer and greater than zero.');
}
return $this->redis->setex($key, $ttl, $value);
}
}