From 17e5dbd7bd0364e27a33f1a7dab91cf33d5dcabc Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 04 三月 2026 11:52:12 +0800
Subject: [PATCH] 增强Redis缓存服务与设备通信优化
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Connection/RedisConnectionManager.cs | 16 +++++-----------
1 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Connection/RedisConnectionManager.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Connection/RedisConnectionManager.cs
index bc37709..a5e772f 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Connection/RedisConnectionManager.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Connection/RedisConnectionManager.cs
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using System.Linq;
+using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_RedisService.Options;
namespace WIDESEAWCS_RedisService.Connection
@@ -21,8 +22,6 @@
{
// 寮哄埗璁块棶Value鏉ヨЕ鍙戣繛鎺ュ垱寤�
var connected = _connection.Value.IsConnected;
- _logger.LogDebug("IsConnected妫�鏌�: IsValueCreated={IsValueCreated}, IsConnected={Connected}",
- _connection.IsValueCreated, connected);
return connected;
}
catch (Exception ex)
@@ -37,22 +36,17 @@
{
_options = options.Value;
_logger = logger;
- _logger.LogInformation("RedisConnectionManager鏋勯�犲紑濮�, ConnectionString={ConnectionString}, Enabled={Enabled}",
- _options.ConnectionString, _options.Enabled);
_connection = new Lazy<ConnectionMultiplexer>(CreateConnection);
- _logger.LogInformation("RedisConnectionManager鏋勯�犲畬鎴�, Lazy宸插垱寤�");
}
private ConnectionMultiplexer CreateConnection()
{
try
{
- _logger.LogInformation("寮�濮嬪垱寤篟edis杩炴帴, ConnectionString={ConnectionString}", _options.ConnectionString);
var configOptions = ConfigurationOptions.Parse(_options.ConnectionString);
configOptions.AbortOnConnectFail = false;
configOptions.ConnectRetry = _options.ConnectRetry;
configOptions.DefaultDatabase = _options.DefaultDatabase;
- _logger.LogInformation("ConfigurationOptions瑙f瀽瀹屾垚, EndPoints={EndPoints}", string.Join(",", configOptions.EndPoints.Select(e => e.ToString())));
if (_options.EnableSentinel && _options.SentinelEndpoints.Count > 0)
{
@@ -65,16 +59,16 @@
var connection = ConnectionMultiplexer.Connect(configOptions);
connection.ConnectionFailed += (_, e) =>
- _logger.LogError("Redis杩炴帴澶辫触: {FailureType}", e.FailureType);
+ ConsoleHelper.WriteErrorLine($"Redis杩炴帴澶辫触: {e.FailureType}");
connection.ConnectionRestored += (_, e) =>
- _logger.LogInformation("Redis杩炴帴鎭㈠: {EndPoint}", e.EndPoint);
+ ConsoleHelper.WriteSuccessLine($"Redis杩炴帴鎭㈠: {e.EndPoint}");
- _logger.LogInformation("Redis杩炴帴鎴愬姛: {EndPoints}", string.Join(",", configOptions.EndPoints));
+ ConsoleHelper.WriteSuccessLine($"Redis杩炴帴鎴愬姛: {string.Join(",", configOptions.EndPoints)}");
return connection;
}
catch (Exception ex)
{
- _logger.LogError(ex, "Redis杩炴帴鍒涘缓澶辫触");
+ ConsoleHelper.WriteErrorLine($"Redis杩炴帴鍒涘缓澶辫触:{ex.Message}");
throw;
}
}
--
Gitblit v1.9.3