carno-php /
cache
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Redis storing |
||
| 4 | * User: moyo |
||
| 5 | * Date: 15/11/2017 |
||
| 6 | * Time: 5:06 PM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Carno\Cache\Stores; |
||
| 10 | |||
| 11 | use Carno\Cache\Contracts\Storing; |
||
| 12 | use Redis as API; |
||
| 13 | |||
| 14 | class Redis implements Storing |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var API |
||
| 18 | */ |
||
| 19 | private $backend = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Redis constructor. |
||
| 23 | * @param API $backend |
||
| 24 | */ |
||
| 25 | public function __construct($backend) |
||
| 26 | { |
||
| 27 | $this->backend = $backend; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param string $key |
||
| 32 | * @return bool |
||
| 33 | */ |
||
| 34 | public function has(string $key) |
||
| 35 | { |
||
| 36 | return (yield $this->backend->exists($key)) ? true : false; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param string $key |
||
| 41 | * @return mixed |
||
| 42 | */ |
||
| 43 | public function read(string $key) |
||
| 44 | { |
||
| 45 | return yield $this->backend->get($key); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $key |
||
| 50 | * @param mixed $data |
||
| 51 | * @param int $ttl |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function write(string $key, $data, int $ttl = null) |
||
| 55 | { |
||
| 56 | return yield $this->backend->setex($key, $ttl, $data); |
||
|
0 ignored issues
–
show
|
|||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $key |
||
| 61 | * @return bool |
||
| 62 | */ |
||
| 63 | public function remove(string $key) |
||
| 64 | { |
||
| 65 | return (yield $this->backend->del($key)) ? true : false; |
||
|
0 ignored issues
–
show
|
|||
| 66 | } |
||
| 67 | } |
||
| 68 |