Cleanup
This commit is contained in:
parent
b8bb6757a8
commit
b1bba4cbfb
3 changed files with 34 additions and 29 deletions
|
|
@ -265,7 +265,7 @@ class App
|
|||
}
|
||||
|
||||
// If Redis is configured, add it to the pool.
|
||||
if($redis->isAvailable()) {
|
||||
if ($redis->isAvailable()) {
|
||||
$caches[] = new RedisCachePool($redis);
|
||||
}
|
||||
$caches[] = new ArrayCachePool();
|
||||
|
|
@ -290,14 +290,14 @@ class App
|
|||
});
|
||||
|
||||
$container->set(Redis::class, function (EnvironmentService $environmentService) {
|
||||
return (new Redis(
|
||||
return new Redis(
|
||||
$environmentService->get('REDIS_HOST', 'redis'),
|
||||
$environmentService->get('REDIS_PORT', 6379),
|
||||
$environmentService->get('REDIS_TIMEOUT', 0.0)
|
||||
));
|
||||
);
|
||||
});
|
||||
|
||||
$container->set(\Redis::class, function(Redis $redis){
|
||||
$container->set(\Redis::class, function (Redis $redis) {
|
||||
return $redis;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ class Redis extends \Redis
|
|||
private int $port;
|
||||
private int $timeout;
|
||||
|
||||
/** @var Lua\AbstractLuaExtension[] */
|
||||
private array $scripts;
|
||||
|
||||
public function __construct($host, $port = 6379, $timeout = 0.0)
|
||||
{
|
||||
$this->host = $host;
|
||||
|
|
@ -16,22 +19,10 @@ class Redis extends \Redis
|
|||
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)
|
||||
{
|
||||
\Kint::dump($name, $arguments);exit;
|
||||
\Kint::dump($name, $arguments);
|
||||
exit;
|
||||
foreach ($this->scripts as $script) {
|
||||
foreach ($script->getFunctionNames() as $functionName) {
|
||||
if (strtolower($name) == strtolower($functionName)) {
|
||||
|
|
@ -43,9 +34,20 @@ class Redis extends \Redis
|
|||
}
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
if(!$this->isConnected()){
|
||||
try {
|
||||
$this->ping('am I human?');
|
||||
|
||||
return true;
|
||||
} catch (\RedisException $redisException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get($key): void
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
parent::pconnect($this->host, $this->port, $this->timeout);
|
||||
$this->initialiseExtensions();
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
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
|
||||
{
|
||||
protected Redis $redis;
|
||||
private ?bool $redisIsAvailable = null;
|
||||
protected $oldID;
|
||||
private ?bool $redisIsAvailable = null;
|
||||
|
||||
private int $lifetime = 43200;
|
||||
private array $dirtyCheck = [];
|
||||
|
|
@ -75,10 +75,12 @@ class SessionService implements \SessionHandlerInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
public function useRedis() : bool {
|
||||
if($this->redisIsAvailable === null){
|
||||
public function useRedis(): bool
|
||||
{
|
||||
if ($this->redisIsAvailable === null) {
|
||||
$this->redisIsAvailable = $this->redis->isAvailable();
|
||||
}
|
||||
|
||||
return $this->redisIsAvailable;
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +97,7 @@ class SessionService implements \SessionHandlerInterface
|
|||
}
|
||||
|
||||
$result = '';
|
||||
if($this->useRedis()) {
|
||||
if ($this->useRedis()) {
|
||||
$serialised = $this->redis->get("session:{$session_id}");
|
||||
if (null != $serialised) {
|
||||
if (!empty($this->oldID)) {
|
||||
|
|
@ -119,9 +121,10 @@ class SessionService implements \SessionHandlerInterface
|
|||
/**
|
||||
* @param string $session_id
|
||||
* @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
|
||||
{
|
||||
if ($this->useAPCU()) {
|
||||
$dirty = crc32(apcu_fetch('read-'.$session_id)) != crc32($session_data);
|
||||
|
|
@ -134,8 +137,8 @@ class SessionService implements \SessionHandlerInterface
|
|||
$this->redis->expire("session:{$session_id}", $this->getLifetime());
|
||||
}
|
||||
|
||||
if($this->useAPCU()) {
|
||||
apcu_store('read-' . $session_id, $session_data);
|
||||
if ($this->useAPCU()) {
|
||||
apcu_store('read-'.$session_id, $session_data);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue