redis check
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
root
2024-08-12 19:59:59 +02:00
parent e7f58109c2
commit 8399a6b3bb
4 changed files with 62 additions and 16 deletions

View File

@@ -12,25 +12,26 @@ function ping_redis() {
else return false;
}
function check_redis($group="schedulerin") {
function check_redis($group="scheduler_in") {
global $REDIS_HOST;
$redis = new Redis();
$redis->connect($REDIS_HOST);
if ($redis->ping()) {
$members = $redis->sMembers($group); // redis-cli -h safebox-redis smembers generated
$members = $redis->sMembers($group); // redis-cli -h redis-server smembers $group
//print_r($members);
foreach ($members as $member) {
$value = $redis->get($member);
$json_data = base64_decode($value);
$data = json_decode($json_data);
$data = json_decode($json_data,true);
if ($data === null) {
echo "JSON read error...";
// TODO json error
}
else {
return $data;
}
}
}
@@ -43,12 +44,12 @@ function redis_get($key) {
$redis = new Redis();
$redis->connect($REDIS_HOST);
if ($redis->ping()) {
//$arList = $redis->keys("*"); // ? redis-cli -h safebox-redis keys "*"
//$arList = $redis->keys("*"); // ? redis-cli -h redis-server keys "*"
//echo "Stored keys in redis:";
//print_r($arList);
if ($redis->exists($key)) {
$value = $redis->get($key);
//redis-cli -h safebox-redis get $key
//redis-cli -h redis-server get $key
return base64_decode($value);
} else {
echo "Key does not exist: $key";
@@ -67,10 +68,10 @@ function redis_set($key, $value) {
if ($redis->ping()) {
if (!$redis->exists($key)) {
//redis-cli -h redis set $key "$value"
//redis-cli -h redis sadd webin $key
//redis-cli -h redis smembers webin
//redis-cli -h redis sadd web_in $key
//redis-cli -h redis smembers web_in
$redis->set($key, base64_encode($value));
$redis->sAdd('webin', $key);
$redis->sAdd('web_in', $key);
} else {
echo "Key already exist: $key";
}
@@ -83,9 +84,9 @@ function redis_remove($key) {
$redis->connect($REDIS_HOST);
// $redis->auth('password');
if ($redis->ping()) {
//redis-cli -h redis srem webout $key
//redis-cli -h redis srem web_out $key
//redis-cli -h redis del $key
$redis->srem("webout", $key);
$redis->srem("web_out", $key);
$redis->del($key);
}
}

View File

@@ -25,18 +25,46 @@
<div class="progress-value"></div>
</div>
</div>
<div><a href="install.html" class="stop">STOP</a></div>
<div><a href="install.html" class="stop">STOP AND START INSTALL</a></div>
<br>
<br>
<div id="redis"></div>
<div id="previous">Scanning for previous install. Please wait...</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.6/dist/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.2.1/dist/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script>
$(function() {
setTimeout(redirectToPage, 10000);
//$("#previous").html('Scanning for previous install. Please wait...');
var url = 'scan.php?op=redis';
$.get(url, function(data){
if (data=='OK') {
$("#redis").html('Redis server - OK');
}
else {
$("#redis").html('Redis server is not available...');
}
});
var url = 'scan.php?op=init';
$.get(url, function(data){
if (data=='OK') {
$("#previous").html('Previous install has found...');
setTimeout(redirectToManage, 3000);
}
else {
$("#previous").html('No previous install has found...');
setTimeout(redirectToInstall, 3000);
}
});
//setTimeout(redirectToManage, 10000);
$(".progress").each(function() {
@@ -95,7 +123,11 @@ $(function() {
return angle;
}
function redirectToPage() {
function redirectToInstall() {
window.location.href = 'install.html';
}
function redirectToManage() {
window.location.href = 'manage.html';
}
});

View File

@@ -28,7 +28,7 @@ if ($_POST["ADDITIONALS"]=="yes") {
$json = json_encode($_POST, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
//echo $json;
$op = "install-".date("YmdHis");
$op = "install:".date("YmdHis");
redis_set($op,$json);
//echo redis_get($op);

View File

@@ -8,11 +8,24 @@ switch ($_GET["op"]) {
if ($ret===false) {
echo "Can't ping redis-server";
}
else echo true;
else echo "OK";
} catch (RedisException $e) {
echo "RedisException caught: " . $e->getMessage();
}
break;
case "init":
$arr = array("STATUS" => 0);
$json = json_encode($arr, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
$op = "init:".date("YmdHis");
redis_set($op,$json);
break;
case "init_check":
$data = check_redis("web_out");
if ($data["STATUS"]==2) echo "NEW";
elseif ($data["STATUS"]==1) echo "EXISTS";
else echo "WAIT";
break;
case "docker":
echo true;
break;