Cleanup
This commit is contained in:
parent
b8bb6757a8
commit
b1bba4cbfb
3 changed files with 34 additions and 29 deletions
|
|
@ -290,11 +290,11 @@ class App
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set(Redis::class, function (EnvironmentService $environmentService) {
|
$container->set(Redis::class, function (EnvironmentService $environmentService) {
|
||||||
return (new Redis(
|
return new Redis(
|
||||||
$environmentService->get('REDIS_HOST', 'redis'),
|
$environmentService->get('REDIS_HOST', 'redis'),
|
||||||
$environmentService->get('REDIS_PORT', 6379),
|
$environmentService->get('REDIS_PORT', 6379),
|
||||||
$environmentService->get('REDIS_TIMEOUT', 0.0)
|
$environmentService->get('REDIS_TIMEOUT', 0.0)
|
||||||
));
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set(\Redis::class, function (Redis $redis) {
|
$container->set(\Redis::class, function (Redis $redis) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ class Redis extends \Redis
|
||||||
private int $port;
|
private int $port;
|
||||||
private int $timeout;
|
private int $timeout;
|
||||||
|
|
||||||
|
/** @var Lua\AbstractLuaExtension[] */
|
||||||
|
private array $scripts;
|
||||||
|
|
||||||
public function __construct($host, $port = 6379, $timeout = 0.0)
|
public function __construct($host, $port = 6379, $timeout = 0.0)
|
||||||
{
|
{
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
|
@ -16,22 +19,10 @@ class Redis extends \Redis
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isAvailable() : bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->ping('am I human?');
|
|
||||||
return true;
|
|
||||||
}catch(\RedisException $redisException){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Lua\AbstractLuaExtension[] */
|
|
||||||
private array $scripts;
|
|
||||||
|
|
||||||
public function __call($name, $arguments)
|
public function __call($name, $arguments)
|
||||||
{
|
{
|
||||||
\Kint::dump($name, $arguments);exit;
|
\Kint::dump($name, $arguments);
|
||||||
|
exit;
|
||||||
foreach ($this->scripts as $script) {
|
foreach ($this->scripts as $script) {
|
||||||
foreach ($script->getFunctionNames() as $functionName) {
|
foreach ($script->getFunctionNames() as $functionName) {
|
||||||
if (strtolower($name) == strtolower($functionName)) {
|
if (strtolower($name) == strtolower($functionName)) {
|
||||||
|
|
@ -43,7 +34,18 @@ class Redis extends \Redis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key)
|
public function isAvailable(): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->ping('am I human?');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (\RedisException $redisException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($key): void
|
||||||
{
|
{
|
||||||
if (!$this->isConnected()) {
|
if (!$this->isConnected()) {
|
||||||
parent::pconnect($this->host, $this->port, $this->timeout);
|
parent::pconnect($this->host, $this->port, $this->timeout);
|
||||||
|
|
@ -62,6 +64,6 @@ class Redis extends \Redis
|
||||||
|
|
||||||
public function connect($host, $port = 6379, $timeout = 0.0, $reserved = null, $retryInterval = 0, $readTimeout = 0.0): void
|
public function connect($host, $port = 6379, $timeout = 0.0, $reserved = null, $retryInterval = 0, $readTimeout = 0.0): void
|
||||||
{
|
{
|
||||||
throw new \RedisException("Do not directly call connect()");
|
throw new \RedisException('Do not directly call connect()');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ use Benzine\Redis\Redis;
|
||||||
class SessionService implements \SessionHandlerInterface
|
class SessionService implements \SessionHandlerInterface
|
||||||
{
|
{
|
||||||
protected Redis $redis;
|
protected Redis $redis;
|
||||||
private ?bool $redisIsAvailable = null;
|
|
||||||
protected $oldID;
|
protected $oldID;
|
||||||
|
private ?bool $redisIsAvailable = null;
|
||||||
|
|
||||||
private int $lifetime = 43200;
|
private int $lifetime = 43200;
|
||||||
private array $dirtyCheck = [];
|
private array $dirtyCheck = [];
|
||||||
|
|
@ -75,10 +75,12 @@ class SessionService implements \SessionHandlerInterface
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function useRedis() : bool {
|
public function useRedis(): bool
|
||||||
|
{
|
||||||
if ($this->redisIsAvailable === null) {
|
if ($this->redisIsAvailable === null) {
|
||||||
$this->redisIsAvailable = $this->redis->isAvailable();
|
$this->redisIsAvailable = $this->redis->isAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->redisIsAvailable;
|
return $this->redisIsAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +121,8 @@ class SessionService implements \SessionHandlerInterface
|
||||||
/**
|
/**
|
||||||
* @param string $session_id
|
* @param string $session_id
|
||||||
* @param string $session_data
|
* @param string $session_data
|
||||||
* @return bool Always returns true.
|
*
|
||||||
|
* @return bool always returns true
|
||||||
*/
|
*/
|
||||||
public function write($session_id, $session_data): bool
|
public function write($session_id, $session_data): bool
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue