From 966524013a821b9e63d8cfdf5a71f5bf0e362297 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Fri, 26 Apr 2024 12:53:02 +0800 Subject: [PATCH] =?UTF-8?q?1=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B=202=20=E5=A2=9E=E5=8A=A0redis=E8=A1=A8?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=EF=BC=9B=203=20index=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=A4=84=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Txgy.RBS.DTO/RedisInfoDTO.cs | 47 ++++++ Txgy.RBS.DTO/ResultDTO.cs | 7 + Txgy.RBS.DbModel/Models/project_info.cs | 7 +- Txgy.RBS.DbModel/Models/redis_server.cs | 48 ++++++ Txgy.RBS.DbModel/Models/station_file.cs | 2 +- Txgy.RBS.DbModel/Models/time_tab.cs | 6 +- Txgy.RBS.Framework/CommonData.cs | 4 + .../FileWatcherHelper/FilesWatcherService.cs | 155 ++++++++++++++++++ Txgy.RBS.Framework/Models/MsEventModel.cs | 6 +- Txgy.RBS.Framework/ProcessConfig.cs | 8 +- .../RedisHelper/Init/RedisManager.cs | 1 + Txgy.RBS.IServices/AutoMapObject.cs | 3 +- Txgy.RBS.IServices/IResultInfoService.cs | 16 +- .../Controllers/ProjectInfoController.cs | 10 +- .../Controllers/ResultInfoController.cs | 31 +++- Txgy.RBS.Server.WebApi/Program.cs | 7 +- .../Register/HostBuilderExtend.cs | 40 ++++- .../Txgy.RBS.Server.WebApi.csproj | 2 +- Txgy.RBS.Server.WebApi/appsettings.json | 10 ++ Txgy.RBS.Server.WebApi/rbs_server_db.db | Bin 753664 -> 753664 bytes Txgy.RBS.Services/ProcessManagerService.cs | 150 +++++++++++++---- Txgy.RBS.Services/ProjectInfoService.cs | 50 +++--- Txgy.RBS.Services/ResultInfoService.cs | 57 +++++++ program/server/server_log.txt | 32 ++++ 24 files changed, 620 insertions(+), 79 deletions(-) create mode 100644 Txgy.RBS.DTO/RedisInfoDTO.cs create mode 100644 Txgy.RBS.DbModel/Models/redis_server.cs create mode 100644 Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs diff --git a/Txgy.RBS.DTO/RedisInfoDTO.cs b/Txgy.RBS.DTO/RedisInfoDTO.cs new file mode 100644 index 0000000..06bc67a --- /dev/null +++ b/Txgy.RBS.DTO/RedisInfoDTO.cs @@ -0,0 +1,47 @@ +using SqlSugar; +using System; +using System.Linq; +using System.Text; + +namespace Txgy.RBS.DTO +{ + /// + /// + /// + public class RedisInfoDTO + { + public RedisInfoDTO() + { + + + } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int id { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string name { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string url { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int port { get; set; } + + } +} diff --git a/Txgy.RBS.DTO/ResultDTO.cs b/Txgy.RBS.DTO/ResultDTO.cs index 8e46042..67b7c24 100644 --- a/Txgy.RBS.DTO/ResultDTO.cs +++ b/Txgy.RBS.DTO/ResultDTO.cs @@ -35,6 +35,12 @@ namespace Txgy.RBS.DTO /// public string otime { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public double? xlon { get; set; } /// /// Desc: /// Default: @@ -99,5 +105,6 @@ namespace Txgy.RBS.DTO /// public double? seismic_direction { get; set; } + public string json_str { set; get; } } } diff --git a/Txgy.RBS.DbModel/Models/project_info.cs b/Txgy.RBS.DbModel/Models/project_info.cs index 231a9a0..fab34ae 100644 --- a/Txgy.RBS.DbModel/Models/project_info.cs +++ b/Txgy.RBS.DbModel/Models/project_info.cs @@ -1,6 +1,8 @@ using SqlSugar; using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Runtime.Serialization; using System.Text; namespace Txgy.RBS.DbModel.Models @@ -182,10 +184,11 @@ namespace Txgy.RBS.DbModel.Models public int push_wx_company_id { get; set; } [Navigate(NavigateType.OneToOne, nameof(project_id))] - public station_file stationFile { get; set; } + // [SugarColumn(IsIgnore = true)] + public station_file station_file { get; set; } [Navigate(NavigateType.OneToOne, nameof(project_id))] - public time_tab time_tab { get; set; } + public time_tab time_tab { get; set; } } } diff --git a/Txgy.RBS.DbModel/Models/redis_server.cs b/Txgy.RBS.DbModel/Models/redis_server.cs new file mode 100644 index 0000000..fc90aa4 --- /dev/null +++ b/Txgy.RBS.DbModel/Models/redis_server.cs @@ -0,0 +1,48 @@ +using SqlSugar; +using System; +using System.Linq; +using System.Text; + +namespace Txgy.RBS.DbModel.Models +{ + /// + /// + /// + public class redis_server + { + public redis_server() + { + + + } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + [SugarColumn(IsPrimaryKey = true,IsIdentity =true)] + public int id { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string name { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string url { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int port { get; set; } + + } +} diff --git a/Txgy.RBS.DbModel/Models/station_file.cs b/Txgy.RBS.DbModel/Models/station_file.cs index 0a64b1c..dd54158 100644 --- a/Txgy.RBS.DbModel/Models/station_file.cs +++ b/Txgy.RBS.DbModel/Models/station_file.cs @@ -15,7 +15,7 @@ namespace Txgy.RBS.DbModel.Models /// Default: /// Nullable:True /// - [SugarColumn(IsPrimaryKey = true,IsIdentity =true)] + [SugarColumn(IsPrimaryKey = true)] public int id { get; set; } /// diff --git a/Txgy.RBS.DbModel/Models/time_tab.cs b/Txgy.RBS.DbModel/Models/time_tab.cs index 19e6f01..29d15b2 100644 --- a/Txgy.RBS.DbModel/Models/time_tab.cs +++ b/Txgy.RBS.DbModel/Models/time_tab.cs @@ -8,7 +8,7 @@ namespace Txgy.RBS.DbModel.Models /// /// /// - public partial class time_tab + public class time_tab { public time_tab() { @@ -20,7 +20,7 @@ namespace Txgy.RBS.DbModel.Models /// Default: /// Nullable:True /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true)] public int id { get; set; } /// @@ -28,7 +28,7 @@ namespace Txgy.RBS.DbModel.Models /// Default: /// Nullable:True /// - public int? project_id { get; set; } + public int project_id { get; set; } /// /// Desc: diff --git a/Txgy.RBS.Framework/CommonData.cs b/Txgy.RBS.Framework/CommonData.cs index 461a8d7..5356d83 100644 --- a/Txgy.RBS.Framework/CommonData.cs +++ b/Txgy.RBS.Framework/CommonData.cs @@ -10,9 +10,13 @@ namespace Txgy.RBS.Framework public class CommonData { public static string BaseProjectPath { get; set; } = "d:\\Project"; + public static string RedisDefaultPath { get; set; } = "program\\server"; + public static string ApmsDefaultPath { get; set; } = "program\\apms\\gw.apms.json"; public static string RecvDefaultPath { get; set; } = "program\\recvmqtt\\gw.recvmqtt.json"; + public static string RedisPublish { get; set; } = "server_status"; + /// //From:www.13le.com /// 复制文件夹下所有文件 diff --git a/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs b/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs new file mode 100644 index 0000000..014caaf --- /dev/null +++ b/Txgy.RBS.Framework/FileWatcherHelper/FilesWatcherService.cs @@ -0,0 +1,155 @@ +using ServiceStack.Messaging; +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; +using Txgy.RBS.Framework.Models; + +namespace Txgy.RBS.Framework.FileWatcherHelper +{ + public class FilesWatcherService + { + public FilesWatcherService(int proId, string projectName, string path) + { + projectId = proId; + proName = projectName; + watcherPath = path; + // string filter = "*.txt"; + // WatcherPath = AppDomain.CurrentDomain.BaseDirectory; + // InitializeParams(filter, watcherPath); + } + private string watcherPath; + + public string WatcherPath + { + get { return watcherPath; } + } + private string proName; + + public string ProName + { + get { return proName; } + } + private int projectId; + + public int ProjectId + { + get { return projectId; } + } + + public DateTime StartTime { get; set; } + + public void Start() + { + WatchStartOrSopt(true); + StartTime = DateTime.Now; + } + + public void Stop() + { + WatchStartOrSopt(false); + + } + public Action WatcherFileChanged; + public void InitializeParams(string fileFilter="*.index") + { + + //如果设置的目录不存在设置到根目录 + if (!File.Exists(watcherPath)) + { + Directory.CreateDirectory(watcherPath); + // watcherPath = AppDomain.CurrentDomain.BaseDirectory; + } + watcher = new FileSystemWatcher(); + //初始化监听 + watcher.BeginInit(); + + //设置需要监听的更改类型(如:文件或者文件夹的属性,文件或者文件夹的创建时间;NotifyFilters枚举的内容) + watcher.NotifyFilter = NotifyFilters.Attributes + | NotifyFilters.CreationTime + | NotifyFilters.DirectoryName + | NotifyFilters.FileName + | NotifyFilters.LastAccess + | NotifyFilters.LastWrite + | NotifyFilters.Security + | NotifyFilters.Size; + //设置监听的路径 + watcher.Path = watcherPath; + watcher.Changed += new FileSystemEventHandler(Watcher_Changed); + // watcher.Created += Watcher_Created; + watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted); + watcher.Renamed += new RenamedEventHandler(Watcher_Renamed); + watcher.Error += OnError; + + //设置监听文件类型 + watcher.Filter = fileFilter; + //设置是否监听子目录 + watcher.IncludeSubdirectories = false; + //设置是否启用监听 + watcher.EnableRaisingEvents = false; + watcher.EndInit(); + + } + + private void OnError(object sender, ErrorEventArgs e) + { + + } + private void Watcher_Changed(object sender, FileSystemEventArgs e) + { + Thread.Sleep(100); + // string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); + watcher.EnableRaisingEvents = false; + Debug.WriteLine($"最后修改时间:{lastWriteTime}"); + string lastLine = File.ReadLines(e.FullPath).Last().Trim(); + var msEvent = new MsEventModel(lastLine) { CurrentTime = DateTime.Now }; + msEvent.ProjectId = this.ProjectId; + msEvent.ProjectName = this.ProName; + WatcherFileChanged?.Invoke(msEvent, e); + watcher.EnableRaisingEvents = true; + } + + private void Watcher_Renamed(object sender, RenamedEventArgs e) + { + + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + } + + private void Watcher_Created(object sender, FileSystemEventArgs e) + { + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + } + + private void Watcher_Deleted(object sender, FileSystemEventArgs e) + { + + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + + } + + /// + /// 启动或者停止监听 + /// + /// True:启用监听,False:关闭监听 + private void WatchStartOrSopt(bool IsEnableRaising) + { + watcher.EnableRaisingEvents = IsEnableRaising; + } + + private FileSystemWatcher watcher = new FileSystemWatcher(); + } +} diff --git a/Txgy.RBS.Framework/Models/MsEventModel.cs b/Txgy.RBS.Framework/Models/MsEventModel.cs index 7b5fe2a..e7167fb 100644 --- a/Txgy.RBS.Framework/Models/MsEventModel.cs +++ b/Txgy.RBS.Framework/Models/MsEventModel.cs @@ -5,7 +5,8 @@ namespace Txgy.RBS.Framework.Models { public class MsEventModel { - public int ID { get; set; } + public int ProjectId { get; set; } + public string ProjectName { get; set; } public DateTime CurrentTime { get; set; } public DateTime OriginTime { get; set; } public double EastCoordinate { get; set; } @@ -14,7 +15,8 @@ namespace Txgy.RBS.Framework.Models public double ML { get; set; } public double Energy { get; set; } - + public int PhasesCount { get; set; } + public int AmpsCount { get; set; } public int EarthquakeSource { get; set; } public bool IsSend { get => isSend; set => isSend = value; } diff --git a/Txgy.RBS.Framework/ProcessConfig.cs b/Txgy.RBS.Framework/ProcessConfig.cs index f246270..94ed6ca 100644 --- a/Txgy.RBS.Framework/ProcessConfig.cs +++ b/Txgy.RBS.Framework/ProcessConfig.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; +using Txgy.RBS.Framework.FileWatcherHelper; namespace Txgy.RBS.Framework { @@ -11,7 +13,7 @@ namespace Txgy.RBS.Framework /// /// server程序 /// - public ProcessInfo Server { get; set; } + // public ProcessInfo Server { get; set; } /// /// Recv程序 /// @@ -21,5 +23,9 @@ namespace Txgy.RBS.Framework /// public ProcessInfo Apms { get; set; } + + + [JsonIgnore] + public FilesWatcherService FilesWatcherService { get; set; } } } diff --git a/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs b/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs index 0c92439..8077634 100644 --- a/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs +++ b/Txgy.RBS.Framework/RedisHelper/Init/RedisManager.cs @@ -38,6 +38,7 @@ namespace Txgy.RBS.Framework.RedisHelper.Init MaxWritePoolSize = RedisConfigInfo.MaxWritePoolSize, MaxReadPoolSize = RedisConfigInfo.MaxReadPoolSize, AutoStart = RedisConfigInfo.AutoStart, + DefaultDb=2 }); } diff --git a/Txgy.RBS.IServices/AutoMapObject.cs b/Txgy.RBS.IServices/AutoMapObject.cs index b88ed01..f63ab9a 100644 --- a/Txgy.RBS.IServices/AutoMapObject.cs +++ b/Txgy.RBS.IServices/AutoMapObject.cs @@ -14,13 +14,14 @@ namespace Txgy.RBS.IServices CreateMap().ReverseMap(); CreateMap() .ForMember(p => p.timeTab, pd => pd.MapFrom(s => s.time_tab)) - .ForMember(p => p.stationFile, pd => pd.MapFrom(s => s.stationFile)).ReverseMap(); + .ForMember(p => p.stationFile, pd => pd.MapFrom(s => s.station_file)).ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } diff --git a/Txgy.RBS.IServices/IResultInfoService.cs b/Txgy.RBS.IServices/IResultInfoService.cs index fa2649f..efabf4d 100644 --- a/Txgy.RBS.IServices/IResultInfoService.cs +++ b/Txgy.RBS.IServices/IResultInfoService.cs @@ -19,8 +19,20 @@ namespace Txgy.RBS.IServices ApiResult UpdateResultInfo(ResultDTO resultJsonDTO); ResultDTO GetResultInfo(int id); - + + List GetResultInfo(string projectName, DateTime startTime,DateTime endTime); + List GetAllResultInfo(); - + + List GetAllRidesInfo(); + + ApiResult AddRedisInfo(RedisInfoDTO redisServerDTO); + + ApiResult DeleteRedisInfo(int id); + + ApiResult UpdateRedisInfo(RedisInfoDTO redisServerDTO); + + RedisInfoDTO GetRedisInfo(int id); + } } diff --git a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs index ecdb3bc..6f2ee82 100644 --- a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs +++ b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs @@ -32,6 +32,12 @@ namespace Txgy.RBS.Server.WebApi.Controllers [HttpPost] public ApiResult AddProjectInfo(ProjectInfoDTO project) { + //var pro= _projectInfoService.GetProjectInfo(1); + // pro.id=project.id; + // pro.project_id = project.project_id; + // pro.project_name = project.project_name; + // pro.moni_layer = project.moni_layer; + // pro.moni_num = project.moni_num; return _projectInfoService.AddProjectInfo(project); } @@ -144,8 +150,8 @@ namespace Txgy.RBS.Server.WebApi.Controllers System.IO.File.WriteAllText(Path.Combine(path, CommonData.RecvDefaultPath), recvJson); _processConfig.RecvMqtt.ProPath = Path.Combine(path, _processConfig.RecvMqtt.ProPath); } - _processConfig.Server.ProPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _processConfig.Server.ProPath); - res= _projectInfoService.StartProject(curProject.project_name, _processConfig); + _processConfig.FilesWatcherService = new Framework.FileWatcherHelper.FilesWatcherService(curProject.project_id,curProject.project_name,apm.savepath); + res= _projectInfoService.StartProject(curProject.project_name, _processConfig); res.Data = curProject; } return res; diff --git a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs index fde3b5b..0848081 100644 --- a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs +++ b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs @@ -19,7 +19,7 @@ namespace Txgy.RBS.Server.WebApi.Controllers this._resultInfoService = resultInfoService; } [HttpPost] - public ApiResult AddProjectInfo(ResultDTO resultDTO) + public ApiResult AddResultInfo(ResultDTO resultDTO) { return _resultInfoService.AddResultInfo(resultDTO); } @@ -41,11 +41,40 @@ namespace Txgy.RBS.Server.WebApi.Controllers { return _resultInfoService.GetResultInfo(id); } + [HttpGet] + public List GetResultInfo(string projectName, DateTime startTime, DateTime endTime) + { + return _resultInfoService.GetResultInfo(projectName.Trim(), startTime, endTime); + } [HttpGet] public List GetAllResultInfo() { return _resultInfoService.GetAllResultInfo(); } + + [HttpPost] + public ApiResult AddRedisInfo(RedisInfoDTO redisDTO) + { + return _resultInfoService.AddRedisInfo(redisDTO); + } + + [HttpDelete("{id}")] + public ApiResult DeleteRedisInfo(int id) + { + return _resultInfoService.DeleteRedisInfo(id); + } + + [HttpPost] + public ApiResult UpdateRedisInfo(RedisInfoDTO redisDTO) + { + return _resultInfoService.UpdateRedisInfo(redisDTO); + } + + [HttpGet] + public List GetAllRedisInfo() + { + return _resultInfoService.GetAllRidesInfo(); + } } } diff --git a/Txgy.RBS.Server.WebApi/Program.cs b/Txgy.RBS.Server.WebApi/Program.cs index 69a7765..f34533d 100644 --- a/Txgy.RBS.Server.WebApi/Program.cs +++ b/Txgy.RBS.Server.WebApi/Program.cs @@ -7,9 +7,6 @@ using Txgy.RBS.Server.WebApi.Register; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. - -builder.Register(); //ҵ߼ע //֧Automapperӳ builder.Services.AddAutoMapper(typeof(AutoMapObject)); @@ -19,6 +16,10 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // ñػ builder.Services.AddMemoryCache(); + +//ҵ߼ע +builder.Register(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs index 5869b67..cc3c21a 100644 --- a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs +++ b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs @@ -3,8 +3,10 @@ using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using SqlSugar; +using System.Diagnostics; using System.Reflection; using Txgy.RBS.Framework; +using Txgy.RBS.Framework.RedisHelper.Init; using Txgy.RBS.Framework.RedisHelper.Service; using Txgy.RBS.Services; @@ -14,7 +16,6 @@ namespace Txgy.RBS.Server.WebApi.Register { public static void Register(this WebApplicationBuilder applicationBuilder) { - //替换容器Autofac applicationBuilder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); applicationBuilder.Host.ConfigureContainer(ConfigurationBinder => @@ -26,7 +27,7 @@ namespace Txgy.RBS.Server.WebApi.Register Assembly serviceAssembly = Assembly.Load("Txgy.RBS.IServices"); ConfigurationBinder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly).AsImplementedInterfaces(); #endregion - var pro= applicationBuilder.Configuration.GetSection("process").Get(); + var pro = applicationBuilder.Configuration.GetSection("process").Get(); ConfigurationBinder.RegisterType().SingleInstance(); #region 注册每个控制器和抽象之间的关系 var controllerBaseType = typeof(ControllerBase); @@ -37,7 +38,7 @@ namespace Txgy.RBS.Server.WebApi.Register #region 注册SqlSugar ConfigurationBinder.Register(context => { - SqlSugarClient client = new SqlSugarClient(new ConnectionConfig() + SqlSugarClient client = new SqlSugarClient(new ConnectionConfig() { ConnectionString = applicationBuilder.Configuration.GetConnectionString("ConnectionSqlite"), // "Data Source=DESKTOP-T2D6ILD;Initial Catalog=LiveBackgroundManagementNew;Persist Security Info=True;User ID=sa;Password=sa123", DbType = DbType.Sqlite, @@ -68,11 +69,40 @@ namespace Txgy.RBS.Server.WebApi.Register ConfigurationBinder.RegisterType(); ConfigurationBinder.RegisterType(); ConfigurationBinder.RegisterType(); - } - #endregion + //启动redis服务 + { + //* Create your Process + Process process = new Process(); + process.Exited += Process_Exited; + process.EnableRaisingEvents = true; + process.StartInfo.FileName = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CommonData.RedisDefaultPath, "server.exe")); + process.StartInfo.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CommonData.RedisDefaultPath); + // process.StartInfo.Arguments = "service.conf"; + Debug.WriteLine($"*******ProcessName:{process.StartInfo.FileName}, arguments:{process.StartInfo.Arguments}*********"); + process.StartInfo.UseShellExecute = true; + process.StartInfo.CreateNoWindow = false; + //* Start process and handlers + Process[] localByName = Process.GetProcessesByName("server"); + + if (localByName.Length != 0) + { + localByName[0].Exited += Process_Exited; + localByName[0].EnableRaisingEvents = true; + process = localByName[0]; + return; + } + bool res = process.Start(); + } + } + #endregion }); + applicationBuilder.Services.Configure(applicationBuilder.Configuration.GetSection("RedisConfigInfo")); + } + + private static void Process_Exited(object? sender, EventArgs e) + { } } } diff --git a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj index 11418b6..08874fb 100644 --- a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj +++ b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj @@ -22,7 +22,7 @@ - PreserveNewest + Never diff --git a/Txgy.RBS.Server.WebApi/appsettings.json b/Txgy.RBS.Server.WebApi/appsettings.json index cfff6b9..41f5c20 100644 --- a/Txgy.RBS.Server.WebApi/appsettings.json +++ b/Txgy.RBS.Server.WebApi/appsettings.json @@ -46,5 +46,15 @@ "ShowState": 0 } }, + "RedisConfigInfo": { + "WriteServerList": "127.0.0.1:6379", + "ReadServerList": "127.0.0.1:6379", + "MaxWritePoolSize": 60, + "MaxReadPoolSize": 60, + "LocalCacheTime": 180, + "AutoStart": true, + "RecordeLog": true + + }, "AllowedHosts": "*" } diff --git a/Txgy.RBS.Server.WebApi/rbs_server_db.db b/Txgy.RBS.Server.WebApi/rbs_server_db.db index 83256133ebd188bbb503a59deddd90f0a1f165cf..a902ceddaf1e09a859b28df89050e628210c1264 100644 GIT binary patch delta 4566 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 Reci>&yLiiKKIZG5e*>G%a9{uc delta 3437 zcmdUxYitzP702(Ld*`*U8MAm@1BMNl@bY8*T+iw%%CU~Cg!iS0G4iLt$=cukUq z#CE|2^0LWPoupK?jY>%$2`*DSA)+Kz)mBwi)s-SuRV11=Riy^nA~i%Rjz!PixsALk zU;3dRYWc^xbLQT;=N|vhxeN~%3=bEKFU?R9LT>|c;5f5q^GepKsG#d(5uUI%2mhkg z+MKt@9dh}VDrrm{B+b%xDU)QAY$HS8dG>b$#w8peS~z5k;dN$vx8QaAPPY}xS*us$ z@gYMMaRJPsW5V2YHS&RBO5o9!%k(5A!qo`x6O^tJ#tlbsiA!13GU2*$ciJD4xq zrcKN)v1u){OKlorc9~6s%;sF71k7@H%|5jPUNakn*I;d;3s}EGnQIm7##XGc>4%Wr zT(44vWN8d(Z~4}Gf9BMJG`s&G(GhBDR3?szvLd^gQ0=P2iWaR;|LL`;)QG-ndgU?S}{Y6AOl7 zLvysQH5zQKt8a`#8L_%b%`qnq37O`OL&5{rFQja|px}vqpNgfv)14b3eYvTQ@y}GJ zu%S~_6PIruyYHVxL#5-2R3m}D5HkKKp9H;P!sd=tENCSnw36a{R&s)L$}4e{hf8g$Guf3n>MQ5!3p4eBdn4bm!r2km@JK3oZA5rYRPjy|x-4VG zvY|tXtohaQ@~GoM*7G16c#xZUkWnYdhj@@%c#vCpklT2W4?96V!h>w&K|Tu8)Ol^E zFNt!|Zse1^uX)#du6ee*KXe~;Q`gsAYt?tuM&%=AP?6== zCpS{g>@;W5XDR0w(wtMjPdT&FoZk7AGmz$d)^TR0IsXDq(lfHyYs{`8 zCps|_@tae#bomm5u3rnH;!tr(ey9k3TSKABP^f3b?=gS%K0Qo(MizO@qJN}D86I;2 zMn31}y$gRjbV$2v`fk%=otz{2!n?vw{1G0+GJ4%?nx%CtD++{AYVMn*;eY3-BrQsw zqvA9t&rwmDljkUu=HxjlOmp%a6{Ij-L92o^ZS2SUW~a*^QBFinnRx zKh6gKtJwDcb*eLN7dsD@EhJmEYZAX9i)eIgP)$`Ko|>5^M8_Sxf|_|nweSjS0wf73c!qHkEp*A=VAUCjpj5_G$_^4@?5z0xkgG1}*|`0N(+=3w#gwKJX^+ z7H|oe27Uls1}xx*0JWRyCCdvp4w=_xLh4Nyt~GB}sxe$+ZjY#ac$0aJnQC)=6__gX zHD)5FR1K!mOoH)Nq?PBpAEa8?Mzd)XObMIUnJG8(YQU74U$0TS@gaWsJjwffH<#35 zM`1l&)4g2NeO%KCuIYY9(?__bzsNOxlxuo`-$_Y+M-6gaALF`yitGAmN7on0w5;Rf z{N;0e^7DN05dYXP|M&>s?8|)f6HY8Ad1#|N)UWW+Pw}Iic20JNAM^!&@E3U^UV>fW d-p8*vA>lC|;y91$tP|BJQAdgE3USX5{R`1rVQ&Bc diff --git a/Txgy.RBS.Services/ProcessManagerService.cs b/Txgy.RBS.Services/ProcessManagerService.cs index a437174..4b6b8f4 100644 --- a/Txgy.RBS.Services/ProcessManagerService.cs +++ b/Txgy.RBS.Services/ProcessManagerService.cs @@ -1,35 +1,52 @@ -using System.Diagnostics; -using Txgy.RBS.Framework.Api; -using Txgy.RBS.Framework; +using Aspose.Cells; using Microsoft.Extensions.Caching.Memory; using System.Collections.Concurrent; -using ServiceStack; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using Newtonsoft.Json.Linq; using System.Data; +using System.Diagnostics; using Txgy.RBS.DTO; -using Aspose.Cells; +using Txgy.RBS.Framework; +using Txgy.RBS.Framework.Api; +using Txgy.RBS.Framework.FileWatcherHelper; using Txgy.RBS.Framework.Models; +using Txgy.RBS.Framework.RedisHelper.Service; +using Txgy.RBS.IServices; namespace Txgy.RBS.Services { public class ProcessManagerService { private readonly IMemoryCache _cache; + private readonly RedisListService _redisList; + private readonly IResultInfoService _resultInfoService; - public ProcessManagerService( IMemoryCache cache) + public ProcessManagerService(RedisListService redisList, IResultInfoService resultInfoService, IMemoryCache cache) { - _cache = cache; MoniTimer.Interval = 10000; MoniTimer.Elapsed += MoniTimer_Elapsed; MoniTimer.Start(); + this._redisList = redisList; + this._resultInfoService = resultInfoService; + _cache = cache; + RedisServer = new ProcessInfo() + { + ProName = "server", + StartTime = DateTime.Now, + State = true + }; } - + public ProcessInfo RedisServer { get; set; } + private void MoniTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) - { + { foreach (var item in ProjectMonitor) { + _redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new + { + projectName = item.Key, + ProName = RedisServer.ProName, + RunState = RedisServer.State?1:0, + RunTime = (DateTime.Now - RedisServer.StartTime).TotalSeconds, + })); foreach (var proValue in item.Value.GetType().GetProperties()) { var pro = proValue.GetValue(item.Value) as ProcessInfo; @@ -38,15 +55,27 @@ namespace Txgy.RBS.Services int sfp = FindProcess(pro); if (sfp != 0) { - Console.WriteLine($"{pro.ProName}程序重启中,path:{pro.ProPath}"); + pro.State = false; + Console.WriteLine($"{pro.ProName}程序重启中, path:{pro.ProPath}"); StartProcess(pro); - Thread.Sleep(20); + Thread.Sleep(20); + } + else + { + pro.State = true; } + _redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new + { + projectName=item.Key, + ProName = pro.ProName, + RunState = sfp == 0 ? 1 : 0, + RunTime = (DateTime.Now - pro.StartTime).TotalSeconds, + })); } - } + } } } - + public ConcurrentDictionary ProjectMonitor = new ConcurrentDictionary(); public void StartMointor(string projectName, ProcessConfig processInfo) @@ -54,6 +83,9 @@ namespace Txgy.RBS.Services if (!ProjectMonitor.ContainsKey(projectName)) { ProjectMonitor.TryAdd(projectName, processInfo); + processInfo.FilesWatcherService.InitializeParams(); + processInfo.FilesWatcherService.Start(); + processInfo.FilesWatcherService.WatcherFileChanged = WatcherChanged; } } System.Timers.Timer MoniTimer { get; set; } = new System.Timers.Timer(); @@ -61,16 +93,60 @@ namespace Txgy.RBS.Services { if (ProjectMonitor.ContainsKey(projectName)) { - ProjectMonitor.TryRemove(projectName, out ProcessConfig pro); + ProjectMonitor.TryRemove(projectName, out ProcessConfig process); + process.FilesWatcherService.Stop(); + foreach (var proValue in process.GetType().GetProperties()) + { + var pro = proValue.GetValue(process) as ProcessInfo; + if (pro != null) + { + _redisList.Publish(CommonData.RedisPublish, Newtonsoft.Json.JsonConvert.SerializeObject(new + { + projectName = projectName, + ProName = pro.ProName, + RunState = 0, + RunTime = (DateTime.Now - pro.StartTime).TotalSeconds, + })); + } + } } } + void WatcherChanged(MsEventModel msEvent, FileSystemEventArgs e) + { + _resultInfoService.AddResultInfo(new ResultDTO + { + project_id = msEvent.ProjectId, + otime = msEvent.OriginTime.ToString("O"), + xlon = msEvent.EastCoordinate, + ylat = msEvent.NorthCoordinate, + depth = msEvent.Depth, + ml = msEvent.ML, + energy = msEvent.Energy, + // rms=msEvent. + phases_count = msEvent.PhasesCount, + amps_count = msEvent.AmpsCount, + }); + _redisList.Publish($"{msEvent.ProjectName}result", Newtonsoft.Json.JsonConvert.SerializeObject(new + { + projectName = msEvent.ProjectName, + ProName = msEvent.OriginTime, + message = msEvent.ToString(), + jsonStr = "" + })); + + } + + #region 方法 public ApiResult StartProject(string projectName, ProcessConfig processConfig) { int res = 0; - if (ProjectMonitor.ContainsKey(projectName)) new ApiResult(); + if (ProjectMonitor.ContainsKey(projectName)) + { + return new ApiResult(); + } foreach (var item in processConfig.GetType().GetProperties()) { var pro = item.GetValue(processConfig) as ProcessInfo; @@ -79,11 +155,11 @@ namespace Txgy.RBS.Services res = StartProcess(pro); if (res != 0) { - break; + continue; } pro.StartTime = DateTime.Now; pro.State = true; - _cache.Set(pro.ProPath, pro); + // _cache.Set(pro.ProPath, pro); Thread.Sleep(10); } } @@ -113,7 +189,7 @@ namespace Txgy.RBS.Services break; } pro.State = false; - _cache.Set(pro.ProPath, pro); + // _cache.Set(pro.ProPath, pro); Thread.Sleep(10); } } @@ -246,7 +322,15 @@ namespace Txgy.RBS.Services } else { - var pro= localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath)); + List pro = null; + if (processInfo.ProName == "server") + { + pro = localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProName)).ToList(); + } + else + { + pro = localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath)).ToList(); + } if (!pro.Any()) { ri = 1; @@ -265,9 +349,14 @@ namespace Txgy.RBS.Services public ApiResult GetState(string projectName, int id) { + ProcessInfo pro = null; + if(id==1) + { + pro = this.RedisServer; + } ProjectMonitor.TryGetValue(projectName, out ProcessConfig process); - if (process == null|| (id<1 || id>3)) { return new ApiResult(); } - ProcessInfo pro = id == 1 ? process.Server : id == 2 ? process.Apms : process.RecvMqtt; + if (process == null || (id < 1|| id > 3)) { return new ApiResult(); } + pro = id == 1 ?pro:(id==2)? process.Apms : process.RecvMqtt; int sfp = FindProcess(pro); if (sfp != 0) { @@ -275,13 +364,14 @@ namespace Txgy.RBS.Services } return new ApiResult { - Code = System.Net.HttpStatusCode.OK, Data = new + Code = System.Net.HttpStatusCode.OK, + Data = new { - name=pro.ProName, - state= sfp == 0 ? 1 : 0, - start_time=pro.StartTime, - running_time=(DateTime.Now-pro.StartTime).TotalSeconds, - } + name = pro.ProName, + state = sfp == 0 ? 1 : 0, + start_time = pro.StartTime, + running_time = (DateTime.Now - pro.StartTime).TotalSeconds, + } }; } diff --git a/Txgy.RBS.Services/ProjectInfoService.cs b/Txgy.RBS.Services/ProjectInfoService.cs index 879c5e6..e2fd343 100644 --- a/Txgy.RBS.Services/ProjectInfoService.cs +++ b/Txgy.RBS.Services/ProjectInfoService.cs @@ -1,4 +1,5 @@ -using AutoMapper; +using Aspose.Cells; +using AutoMapper; using Microsoft.Extensions.Caching.Memory; using SqlSugar; using System; @@ -29,20 +30,31 @@ namespace Txgy.RBS.Services public ApiResult AddProjectInfo(ProjectInfoDTO project) { - project_info project_Info = _iMapper.Map(project); - - var pro = _Client.InsertNav(project_Info).Include(p=>p.stationFile).ThenInclude(t=>t.stations) - .Include(time => time.time_tab).ExecuteCommand(); - if (pro) + try { - return new ApiResult(); + _Client.Ado.BeginTran(); + var projectInfo = _iMapper.Map(project); + //project_id要手动赋值 + projectInfo.project_id= _Client.Queryable().Max(p=>p.project_id)+1; + projectInfo.station_file.project_id= projectInfo.project_id; + projectInfo.time_tab.project_id = projectInfo.project_id; + var pro = _Client.InsertNav(projectInfo).Include(p => p.station_file).ThenInclude(t => t.stations) + .Include(time => time.time_tab).ExecuteCommand(); + + _Client.Ado.CommitTran(); + } + catch (Exception ex) + { + _Client.Ado.RollbackTran(); + return new ApiResult() { Message = $"添加失败,{ex}" }; } - return new ApiResult() { Message = "添加失败" }; + return new ApiResult(); + } public ApiResult DeleteProjectInfo(int id) { - var res = _Client.DeleteNav(p => p.id == id).Include(p => p.stationFile).ThenInclude(t => t.stations) + var res = _Client.DeleteNav(p => p.id == id).Include(p => p.station_file).ThenInclude(t => t.stations) .Include(time => time.time_tab).ExecuteCommand(); if (res) { @@ -53,7 +65,7 @@ namespace Txgy.RBS.Services public List GetAllProjectInfo() { - var projects = _Client.Queryable().Includes(x => x.stationFile, t=>t.stations) + var projects = _Client.Queryable().Includes(x => x.station_file, t=>t.stations) .Includes(ti=>ti.time_tab).ToList(); var projectDTOs= _iMapper.Map>(projects); return projectDTOs; @@ -69,7 +81,7 @@ namespace Txgy.RBS.Services public ApiResult UpdateProjectInfo(ProjectInfoDTO project) { project_info projectInfo = _iMapper.Map(project); - var res = _Client.UpdateNav(projectInfo).Include(p => p.stationFile).ThenInclude(t => t.stations) + var res = _Client.UpdateNav(projectInfo).Include(p => p.station_file).ThenInclude(t => t.stations) .Include(time => time.time_tab).ExecuteCommand(); if (res) { @@ -80,19 +92,8 @@ namespace Txgy.RBS.Services public ProjectInfoDTO GetProjectInfo(int id) { - project_info projectInfo = _Client.Queryable().Includes(x => x.stationFile, t => t.stations).Includes(ti => ti.time_tab).Where(p => p.id == id).First(); - ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo); - - //test - //if (projectInfoDTO != null) - //{ - // projectInfoDTO.id = 6; - // projectInfoDTO.project_id = 9; - // projectInfoDTO.project_name = "tea"; - // projectInfoDTO.moni_layer = 1; - // projectInfoDTO.moni_num = 8; - // var a = UpdateProjectInfo(projectInfoDTO); - //} + var projectInfo = _Client.Queryable().Where(p => p.project_id == id).Includes(p=>p.station_file, s=>s.stations).Includes(p=>p.time_tab).ToList(); + ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo[0]); return projectInfoDTO; } @@ -120,7 +121,6 @@ namespace Txgy.RBS.Services } public ApiResult GetState(string projectName, int id) { - return _processManager.GetState(projectName, id); } diff --git a/Txgy.RBS.Services/ResultInfoService.cs b/Txgy.RBS.Services/ResultInfoService.cs index 647411e..8eadbad 100644 --- a/Txgy.RBS.Services/ResultInfoService.cs +++ b/Txgy.RBS.Services/ResultInfoService.cs @@ -21,6 +21,19 @@ namespace Txgy.RBS.Services this._iMapper = iMapper; } + public ApiResult AddRedisInfo(RedisInfoDTO redisServerDTO) + { + int res = 0; + var redisServer = _iMapper.Map(redisServerDTO); + + res = _Client.Insertable(redisServer).ExecuteCommand(); + if (res > 0) + { + return new ApiResult(); + } + return new ApiResult() { Message = "添加失败" }; + } + public ApiResult AddResultInfo(ResultDTO resultJsonDTO) { int res = 0; @@ -34,6 +47,16 @@ namespace Txgy.RBS.Services return new ApiResult() { Message = "添加失败" }; } + public ApiResult DeleteRedisInfo(int id) + { + int res = _Client.Deleteable(p => p.id == id).ExecuteCommand(); + if (res > 0) + { + return new ApiResult(); + } + return new ApiResult() { Message = "删除失败" }; + } + public ApiResult DeleteResultInfo(int id) { int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); @@ -49,7 +72,18 @@ namespace Txgy.RBS.Services var projects = _Client.Queryable().ToList(); return _iMapper.Map>(projects); } + public List GetAllRidesInfo() + { + var projects = _Client.Queryable().ToList(); + return _iMapper.Map>(projects); + } + public RedisInfoDTO GetRedisInfo(int id) + { + var RedisServer = _Client.Queryable().First(c => c.id == id); + var redisServerDTO = _iMapper.Map(RedisServer); + return redisServerDTO; + } public ResultDTO GetResultInfo(int id) { @@ -58,6 +92,29 @@ namespace Txgy.RBS.Services return resultJsonDTO; } + public List GetResultInfo(string projectName, DateTime startTime, DateTime endTime) + { + var pro= _Client.Queryable().Where(p => p.project_name == projectName).First(); + if (pro == null) + { + return new List(); + } + var results= _Client.Queryable().Where(r => r.project_id == pro.project_id + && (startTime < Convert.ToDateTime(r.otime) && Convert.ToDateTime(r.otime) < endTime)).ToList(); + return _iMapper.Map>(results); + } + + public ApiResult UpdateRedisInfo(RedisInfoDTO redisServerDTO) + { + var redisServer = _iMapper.Map(redisServerDTO); + int res = _Client.Updateable(redisServer).ExecuteCommand(); + if (res > 0) + { + return new ApiResult(); + } + return new ApiResult() { Message = "更新失败" }; + } + public ApiResult UpdateResultInfo(ResultDTO resultJsonDTO) { result result_Json = _iMapper.Map (resultJsonDTO); diff --git a/program/server/server_log.txt b/program/server/server_log.txt index b3167ca..357c7b8 100644 --- a/program/server/server_log.txt +++ b/program/server/server_log.txt @@ -66,3 +66,35 @@ [37440] 17 Apr 14:21:54.835 * Running mode=standalone, port=6379. [37440] 17 Apr 14:21:54.835 # Server initialized [37440] 17 Apr 14:21:54.836 * Ready to accept connections +[7448] 23 Apr 21:40:46.856 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[7448] 23 Apr 21:40:46.865 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=7448, just started +[7448] 23 Apr 21:40:46.865 # Configuration loaded +[7448] 23 Apr 21:40:46.870 * Running mode=standalone, port=6379. +[7448] 23 Apr 21:40:46.870 # Server initialized +[7448] 23 Apr 21:40:46.870 * Ready to accept connections +[35352] 23 Apr 21:42:21.915 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[35352] 23 Apr 21:42:21.916 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=35352, just started +[35352] 23 Apr 21:42:21.916 # Configuration loaded +[35352] 23 Apr 21:42:21.919 * Running mode=standalone, port=6379. +[35352] 23 Apr 21:42:21.919 # Server initialized +[35352] 23 Apr 21:42:21.919 * Ready to accept connections +[30100] 23 Apr 21:42:47.458 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[30100] 23 Apr 21:42:47.459 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=30100, just started +[30100] 23 Apr 21:42:47.460 # Configuration loaded +[30100] 23 Apr 21:42:47.462 * Running mode=standalone, port=6379. +[30100] 23 Apr 21:42:47.462 # Server initialized +[30100] 23 Apr 21:42:47.463 * Ready to accept connections +[29296] 23 Apr 21:43:12.174 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[29296] 23 Apr 21:43:12.175 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=29296, just started +[29296] 23 Apr 21:43:12.175 # Configuration loaded +[29296] 23 Apr 21:43:12.177 * Running mode=standalone, port=6379. +[29296] 23 Apr 21:43:12.177 # Server initialized +[29296] 23 Apr 21:43:12.178 * Ready to accept connections +[29296] 23 Apr 21:43:54.627 # User requested shutdown... +[29296] 23 Apr 21:43:54.629 # Redis is now ready to exit, bye bye... +[14828] 23 Apr 21:45:11.834 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[14828] 23 Apr 21:45:11.834 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=14828, just started +[14828] 23 Apr 21:45:11.835 # Configuration loaded +[14828] 23 Apr 21:45:11.837 * Running mode=standalone, port=6379. +[14828] 23 Apr 21:45:11.837 # Server initialized +[14828] 23 Apr 21:45:11.837 * Ready to accept connections