-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some indentation and type parameter's work
- Loading branch information
Showing
26 changed files
with
472 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,69 @@ | ||
<?php | ||
namespace Cache; | ||
class Redis { | ||
private $expire; | ||
private $cache; | ||
/** | ||
* @var object|\Redis | ||
*/ | ||
private object $redis; | ||
/** | ||
* @var int | ||
*/ | ||
private int $expire; | ||
|
||
public function __construct($expire) { | ||
/** | ||
* Constructor | ||
* | ||
* @param int $expire | ||
*/ | ||
public function __construct(int $expire = 3600) { | ||
$this->expire = $expire; | ||
|
||
$this->cache = new \Redis(); | ||
$this->cache->pconnect(CACHE_HOSTNAME, CACHE_PORT); | ||
$this->redis = new \Redis(); | ||
$this->redis->pconnect(CACHE_HOSTNAME, CACHE_PORT); | ||
} | ||
|
||
public function get($key) { | ||
/** | ||
* Get | ||
* | ||
* @param string $key | ||
* | ||
* @return mixed | ||
*/ | ||
public function get(string $key) { | ||
$data = $this->redis->get(CACHE_PREFIX . $key); | ||
|
||
if ($this->cache->exists(CACHE_PREFIX . $key)) { | ||
$data = $this->cache->get(CACHE_PREFIX . $key); | ||
return json_decode($data, true); | ||
} | ||
|
||
return false; | ||
return json_decode($data, true); | ||
} | ||
|
||
public function set($key, $value, $expire = '') { | ||
/** | ||
* Set | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
* @param int $expire | ||
* | ||
* @return void | ||
*/ | ||
public function set(string $key, $value, int $expire = 0): void { | ||
if (!$expire) { | ||
$expire = $this->expire; | ||
} | ||
|
||
$status = $this->cache->set(CACHE_PREFIX . $key, json_encode($value)); | ||
$status = $this->redis->set(CACHE_PREFIX . $key, json_encode($value)); | ||
|
||
if ($status) { | ||
$this->cache->expire(CACHE_PREFIX . $key, $expire); | ||
$this->redis->expire(CACHE_PREFIX . $key, $expire); | ||
} | ||
|
||
return $status; | ||
} | ||
|
||
public function delete($key) { | ||
$this->cache->del(CACHE_PREFIX . $key); | ||
/** | ||
* Delete | ||
* | ||
* @param string $key | ||
* | ||
* @return void | ||
*/ | ||
public function delete(string $key): void { | ||
$this->redis->del(CACHE_PREFIX . $key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,4 +410,4 @@ public function hasDownload() { | |
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.