Answer the question
In order to leave comments, you need to log in
How to check if Redis is running in Symfony Component Cache?
The project uses Redis as a key:value storage (authorization information is stored)
More precisely, the Symfony Component Cache and RedisAdapter component
is used.
I encounter a situation where sometimes a client's radish falls or they forget to pick it up :)
I can, but they start pushing bugs, but in fact the problem is that the connection to the radish is not available.
You need to somehow check that the radish is working,
write some kind of decorator in which to implement the isConnected check.
But I don’t understand at all in which direction to dig
, it should turn out something like
Decorator
Get
Client->connect
If notConnected
Throw exception
Else
Return client.get
#config/packages/cache.yaml
framework:
cache:
# Redis
app: cache.adapter.redis
default_redis_provider: '%env(resolve:REDIS_URL)%'
<?php
use Symfony\Component\Cache\Adapter\AdapterInterface;
class ContextProcessor {
/**
* @var Symfony\Component\Cache\Adapter\TraceableAdapter
*/
protected $cache;
public function __construct( AdapterInterface $cache) {
$this->cache = $cache;
}
private function getContext(string $token): array
{
// здесь хотелось бы в случае неудачи проверить работает ли редис
$item = $this->cache->getItem($token);
if ($item->isHit()) {
return $this->serializer->decode($item->get());
} else {
throw new HttpException(Response::HTTP_UNAUTHORIZED);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question