Fix REDIS HAS GONE AWAY issues.
This commit is contained in:
parent
744956888b
commit
5a1207271e
3 changed files with 21 additions and 10 deletions
|
|
@ -266,7 +266,7 @@ class App
|
||||||
|
|
||||||
// If Redis is configured, add it to the pool.
|
// If Redis is configured, add it to the pool.
|
||||||
if ($redis->isAvailable()) {
|
if ($redis->isAvailable()) {
|
||||||
$caches[] = new RedisCachePool($redis);
|
$caches[] = new RedisCachePool($redis->getUnderlyingRedis());
|
||||||
}
|
}
|
||||||
$caches[] = new ArrayCachePool();
|
$caches[] = new ArrayCachePool();
|
||||||
|
|
||||||
|
|
@ -298,10 +298,6 @@ class App
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set(\Redis::class, function (Redis $redis) {
|
|
||||||
return $redis;
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->set(Laminator::class, function (ConfigurationService $configurationService, Databases $databases) {
|
$container->set(Laminator::class, function (ConfigurationService $configurationService, Databases $databases) {
|
||||||
return new Laminator(
|
return new Laminator(
|
||||||
APP_ROOT,
|
APP_ROOT,
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ namespace Benzine\Redis\Lua;
|
||||||
|
|
||||||
abstract class AbstractLuaExtension
|
abstract class AbstractLuaExtension
|
||||||
{
|
{
|
||||||
protected \Redis $redis;
|
protected Redis $redis;
|
||||||
protected ?string $hash = null;
|
protected ?string $hash = null;
|
||||||
|
|
||||||
public function __construct(\Redis $redis)
|
public function __construct(Redis $redis)
|
||||||
{
|
{
|
||||||
$this->redis = $redis;
|
$this->redis = $redis;
|
||||||
}
|
}
|
||||||
|
|
@ -29,9 +29,9 @@ abstract class AbstractLuaExtension
|
||||||
public function load(): void
|
public function load(): void
|
||||||
{
|
{
|
||||||
if (!$this->hash) {
|
if (!$this->hash) {
|
||||||
$exists = $this->redis->script('exists', $this->getScript());
|
$exists = $this->getUnderlyingRedis()->script('exists', $this->getScript());
|
||||||
if (!$exists[0]) {
|
if (!$exists[0]) {
|
||||||
$this->hash = $this->redis->script('load', $this->getScript());
|
$this->hash = $this->getUnderlyingRedis()->script('load', $this->getScript());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("Loaded \"%s\" as \"%s\"\n", $this->getFunctionNames()[0], $this->hash);
|
//printf("Loaded \"%s\" as \"%s\"\n", $this->getFunctionNames()[0], $this->hash);
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,25 @@ class Redis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Redis
|
||||||
|
*/
|
||||||
|
public function getUnderlyingRedis(): \Redis
|
||||||
|
{
|
||||||
|
return $this->redis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Logger
|
||||||
|
*/
|
||||||
|
public function getLogger(): Logger
|
||||||
|
{
|
||||||
|
return $this->logger;
|
||||||
|
}
|
||||||
public function isAvailable(): bool
|
public function isAvailable(): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->redis->ping('am I human?');
|
$this->ping('am I human?');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\RedisException $redisException) {
|
} catch (\RedisException $redisException) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue