Answer the question
In order to leave comments, you need to log in
How to ping Redis in PHP?
Just started using Redis. Did a lot of things that are cached. It seems as it should be, there is a key-value in redis, we issue it, or we take it from the database, write it to redis and issue it. I use Predis as a PHP wrapper. But I can’t make the redis part be ignored if there is no redis on the server (it is not yet on the main server, but the code needs to be updated soon).
Predis\Autoloader::register();
self::$redis = new Predis\Client([
'scheme' => 'tcp',
'host' => REDIS_HOST ?: '127.0.0.1',
'port' => REDIS_PORT ?: '6379',
]);
try {
self::$redis->ping();
self::$available = true;
} catch (\Exception $e) {
self::$available = false;
}
Fatal error: in C:\OSPanel\domains\gene.com\vendor\predis\predis\src\Connection\AbstractConnection.php on line 155
namespace Superior;
use \Predis as Predis;
class Redis {
static public $redis;
static private $available = false;
static public function k($key) {
if (self::$redis) {
return self::$redis->get($key);
}
return false;
}
static public function ss($key, $value, $time = 604800) {
if (self::$redis) {
self::$redis->set($key, $value);
self::$redis->expire($key, $time);
}
}
static public function SetUp() {
Predis\Autoloader::register();
self::$redis = new Predis\Client([
'scheme' => 'tcp',
'host' => REDIS_HOST ?: '127.0.0.1',
'port' => REDIS_PORT ?: '6379',
]);
try {
self::$redis->ping();
self::$available = true;
} catch (\Exception $e) {
self::$available = false;
}
}
}
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