Poprawa obsługi połączeń z Redis, w tym zmiana sposobu logowania błędów oraz aktualizacja konfiguracji połączenia. Dodatkowo, dodano zabezpieczenie przed dzieleniem przez zero w widoku dashboardu.

This commit is contained in:
2024-11-12 11:28:27 +01:00
parent be64e16dc7
commit 144df6abf5
4 changed files with 16 additions and 14 deletions

View File

@@ -76,6 +76,9 @@
$min = (int) $this -> sales_grid[$j][$i];
}
}
if ( $max == 0 )
$max = 1;
?>
<div class="table-responsive">
<table class="sales-grid table">

View File

@@ -1,4 +1,4 @@
<?
<?php
class RedisConnection
{
private static $instance = null;
@@ -15,29 +15,28 @@ class RedisConnection
// Próba połączenia z serwerem Redis
if (!$this->redis->connect($config['redis']['host'], $config['redis']['port']))
{
// Logowanie błędu lub inna forma obsługi, zamiast rzucania wyjątku
// Logowanie błędu bez rzucania wyjątku
error_log("Nie udało się połączyć z serwerem Redis.");
$this->redis = null; // Ustawienie na null, aby uniknąć błędów w przyszłości
return; // Wyjście z konstruktora, nie kontynuując autoryzacji
$this->redis = null;
return;
}
// Próba autoryzacji
if (!$this->redis->auth($config['redis']['password']))
{
error_log("Autoryzacja do serwera Redis nie powiodła się.");
$this->redis = null; // Ustawienie na null, aby uniknąć błędów w przyszłości
return; // Wyjście z konstruktora
$this->redis = null;
return;
}
}
catch (\Exception $e)
{
// Obsługa innych potencjalnych wyjątków
// Obsługa wyjątków, bez rzucania błędu
error_log("Błąd podczas połączenia z Redis: " . $e->getMessage());
$this->redis = null; // Ustawienie na null, aby uniknąć błędów w przyszłości
$this->redis = null;
}
}
public static function getInstance()
{
if (self::$instance === null)
@@ -51,4 +50,4 @@ class RedisConnection
{
return $this->redis;
}
}
}

View File

@@ -123,7 +123,7 @@ class Product implements \ArrayAccess
$redis = \RedisConnection::getInstance()->getConnection();
// Check if Redis connection is valid
if ($redis)
if ( $redis )
{
// Try to retrieve the serialized product object from cache
$objectData = $redis->get("shop\product:$product_id:$lang_id:$permutation_hash");

View File

@@ -10,9 +10,9 @@ $config['salt'] = 'dd6c0ee59bf35b208b6d9bf42dd60769';
$config['google-ads-id'] = 'AW-810084545';
$config['baselinker-start'] = '2031-06-09 21:26';
$config['redis']['host'] = '';
$config['redis']['port'] = 0;
$config['redis']['password'] = '';
$config['redis']['host'] = '127.0.0.1';
$config['redis']['port'] = 44090;
$config['redis']['password'] = 'KvCb8A3OJl3JhML1IuD51tD6q9d3TJLu';
$config['debug']['apilo'] = false;
?>