Skip to content

Commit e8f6012

Browse files
committed
Merge branch 'develop'
2 parents 1f6e4ef + 8273f57 commit e8f6012

File tree

2 files changed

+7
-61
lines changed

2 files changed

+7
-61
lines changed

src/extension/CacheTrait.php

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,24 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: arthurkushman
5-
* Date: 04.03.18
6-
* Time: 11:07
7-
*/
82

93
namespace rjapi\extension;
104

11-
12-
use Predis\Client;
13-
use rjapi\helpers\ConfigHelper;
14-
use rjapi\types\ConfigInterface;
5+
use Illuminate\Support\Facades\Redis;
156
use rjapi\types\PhpInterface;
167

8+
/**
9+
* Trait CacheTrait
10+
* @package rjapi\extension
11+
*/
1712
trait CacheTrait
1813
{
19-
/** @var Client $cache */
20-
private $cache;
21-
private $host;
22-
private $port;
23-
24-
public function cacheConn() : void
25-
{
26-
$this->setHostAndPort();
27-
$this->cache = new Client([
28-
'scheme' => 'tcp',
29-
'host' => $this->host,
30-
'port' => $this->port,
31-
]);
32-
// select db
33-
$db = ConfigHelper::getNestedParam(ConfigInterface::CACHE, ConfigInterface::DATABASE);
34-
if ($db !== null) {
35-
$this->cache->select($db);
36-
}
37-
// enter password
38-
$password = env('REDIS_PASSWORD');
39-
if ($password !== null) {
40-
$this->cache->auth($password);
41-
}
42-
}
43-
44-
private function setHostAndPort() : void
45-
{
46-
$cacheEntity = ConfigHelper::getNestedParam(ConfigInterface::CACHE, $this->entity);
47-
$this->host = empty($cacheEntity[ConfigInterface::HOST]) ? null : $cacheEntity[ConfigInterface::HOST];
48-
if ($this->host === null) {
49-
$this->host = env('REDIS_HOST');
50-
if ($this->host === null) {
51-
$this->host = ConfigInterface::DEFAULT_REDIS_HOST;
52-
}
53-
}
54-
55-
$this->port = empty($cacheEntity[ConfigInterface::PORT]) ? null : $cacheEntity[ConfigInterface::PORT];
56-
if ($this->port === null) {
57-
$this->port = env('REDIS_PORT');
58-
if ($this->port === null) {
59-
$this->port = ConfigInterface::DEFAULT_REDIS_PORT;
60-
}
61-
}
62-
}
63-
6414
/**
6515
* @param string $key
6616
* @param \League\Fractal\Resource\Collection | \League\Fractal\Resource\Item $val
6717
* @return mixed
6818
*/
6919
private function set(string $key, $val)
7020
{
71-
return $this->cache->set($key, $this->ser($val));
21+
return Redis::set($key, $this->ser($val));
7222
}
7323

7424
/**
@@ -77,7 +27,7 @@ private function set(string $key, $val)
7727
*/
7828
private function get(string $key)
7929
{
80-
$data = $this->cache->get($key);
30+
$data = Redis::get($key);
8131
if ($data === null) {
8232
return null;
8333
}

src/extension/OptionsTrait.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ private function setConfigOptions(string $calledMethod) : void
8383
$this->configOptions->setIsCached($entityCache[ConfigInterface::ENABLED]);
8484
}
8585
}
86-
87-
if ($this->configOptions->isCached()) {
88-
$this->cacheConn();
89-
}
9086
}
9187

9288
/**

0 commit comments

Comments
 (0)