Added RedisDatabase class

This commit is contained in:
Bofh 2022-12-12 13:51:20 +01:00
parent dd92256817
commit 5c2d180312
2 changed files with 20 additions and 0 deletions

View File

@ -495,3 +495,4 @@ function cronjob_db_create($software, $instance, $sql, $time=3600) {
// classes
require 'classes/PgDatabase.php';
require 'classes/RedisDatabase.php';

19
classes/RedisDatabase.php Normal file
View File

@ -0,0 +1,19 @@
<?php
class RedisDatabase extends Redis {
public function __construct($software, $instance) {
$config = instance_config($software, $instance);
try {
$this->connect($config['redis_host'], $config['redis_port']);
if (isset($config['redis_password']))
$this->auth($config['redis_password']);
} catch (RedisException $e) {
return apiresult(['error' => 'Could not connect to Redis: '.strval($e)]);
}
if ($this->ping())
return true;
return false;
}
}