Redis + RateLimiting
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Core\Objects;
|
||||
|
||||
use Core\Configuration\Configuration;
|
||||
use Core\Configuration\Settings;
|
||||
use Core\Driver\Redis\RedisConnection;
|
||||
use Core\Driver\SQL\Column\Column;
|
||||
use Core\Driver\SQL\Condition\Compare;
|
||||
use Core\Driver\SQL\Condition\CondLike;
|
||||
@@ -25,6 +26,7 @@ class Context {
|
||||
private Configuration $configuration;
|
||||
private Language $language;
|
||||
public ?Router $router;
|
||||
private ?RedisConnection $redis;
|
||||
|
||||
private function __construct() {
|
||||
|
||||
@@ -32,6 +34,7 @@ class Context {
|
||||
$this->session = null;
|
||||
$this->user = null;
|
||||
$this->router = null;
|
||||
$this->redis = null;
|
||||
$this->configuration = new Configuration();
|
||||
$this->setLanguage(Language::DEFAULT_LANGUAGE());
|
||||
|
||||
@@ -52,6 +55,11 @@ class Context {
|
||||
$this->sql->close();
|
||||
$this->sql = null;
|
||||
}
|
||||
|
||||
if ($this->redis && $this->redis->isConnected()) {
|
||||
$this->redis->close();
|
||||
$this->redis = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setLanguage(Language $language): void {
|
||||
@@ -201,4 +209,18 @@ class Context {
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
public function getRedis(): ?RedisConnection {
|
||||
|
||||
if ($this->redis === null) {
|
||||
$settings = $this->getSettings();
|
||||
$connectionData = $settings->getRedisConfiguration();
|
||||
$this->redis = new RedisConnection($this->sql);
|
||||
if (!$this->redis->connect($connectionData)) {
|
||||
$this->redis = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redis;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user