kodedphp /
cache-simple
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /* |
||||||
| 4 | * This file is part of the Koded package. |
||||||
| 5 | * |
||||||
| 6 | * (c) Mihail Binev <[email protected]> |
||||||
| 7 | * |
||||||
| 8 | * Please view the LICENSE distributed with this source code |
||||||
| 9 | * for the full copyright and license information. |
||||||
| 10 | * |
||||||
| 11 | */ |
||||||
| 12 | |||||||
| 13 | namespace Koded\Caching\Client; |
||||||
| 14 | |||||||
| 15 | use Koded\Caching\Cache; |
||||||
| 16 | use Koded\Stdlib\Interfaces\Serializer; |
||||||
| 17 | use function Koded\Caching\verify_key; |
||||||
| 18 | |||||||
| 19 | /** |
||||||
| 20 | * Class RedisClient uses the Redis PHP extension. |
||||||
| 21 | * |
||||||
| 22 | */ |
||||||
| 23 | final class RedisClient implements Cache |
||||||
| 24 | { |
||||||
| 25 | use ClientTrait, MultiplesTrait; |
||||||
| 26 | |||||||
| 27 | private $serializer; |
||||||
| 28 | |||||||
| 29 | 208 | public function __construct(\Redis $client, Serializer $serializer, int $ttl = null) |
|||||
| 30 | { |
||||||
| 31 | 208 | $this->client = $client; |
|||||
| 32 | 208 | $this->serializer = $serializer; |
|||||
| 33 | 208 | $this->ttl = $ttl; |
|||||
| 34 | 208 | } |
|||||
| 35 | |||||||
| 36 | |||||||
| 37 | 68 | public function get($key, $default = null) |
|||||
| 38 | { |
||||||
| 39 | 68 | return $this->has($key) |
|||||
| 40 | 42 | ? $this->serializer->unserialize($this->client->get($key)) |
|||||
| 41 | 51 | : $default; |
|||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | |||||||
| 45 | 83 | public function set($key, $value, $ttl = null) |
|||||
| 46 | { |
||||||
| 47 | 83 | verify_key($key); |
|||||
| 48 | 66 | $expiration = $this->secondsWithGlobalTtl($ttl); |
|||||
| 49 | |||||||
| 50 | 56 | if (null === $ttl && 0 === $expiration) { |
|||||
| 51 | 52 | return $this->client->set($key, $this->serializer->serialize($value)); |
|||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | 5 | if ($expiration > 0) { |
|||||
| 55 | 2 | return $this->client->setex($key, $expiration, $this->serializer->serialize($value)); |
|||||
|
0 ignored issues
–
show
|
|||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | 3 | $this->client->del($key); |
|||||
|
0 ignored issues
–
show
The method
del() does not exist on Koded\Caching\Client\ShmopClient.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 59 | |||||||
| 60 | 3 | return true; |
|||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | |||||||
| 64 | 28 | public function delete($key) |
|||||
| 65 | { |
||||||
| 66 | 28 | if (false === $this->has($key)) { |
|||||
| 67 | 8 | return true; |
|||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | 8 | return 1 === $this->client->del($key); |
|||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | |||||||
| 74 | 206 | public function clear() |
|||||
| 75 | { |
||||||
| 76 | 206 | return $this->client->flushDB(); |
|||||
|
0 ignored issues
–
show
The method
flushDB() does not exist on Koded\Caching\Client\ShmopClient.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 77 | } |
||||||
| 78 | |||||||
| 79 | |||||||
| 80 | 111 | public function has($key) |
|||||
| 81 | { |
||||||
| 82 | 111 | verify_key($key); |
|||||
| 83 | |||||||
| 84 | 60 | return (bool)$this->client->exists($key); |
|||||
|
0 ignored issues
–
show
The method
exists() does not exist on Koded\Caching\Client\ShmopClient.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 85 | } |
||||||
| 86 | } |
||||||
| 87 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.