2026-01-15 17:32:26 +08:00
|
|
|
|
using CommonEntity;
|
|
|
|
|
|
using CSRedis;
|
2026-02-04 18:06:18 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using NLog;
|
|
|
|
|
|
using System.Net;
|
2026-01-15 17:32:26 +08:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BLWLogProduce.Models
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MyPublishRedis
|
|
|
|
|
|
{
|
|
|
|
|
|
public static CSRedisClient? redis4;
|
2026-02-04 18:06:18 +08:00
|
|
|
|
public static CSRedisClient? redis6;
|
2026-01-15 17:32:26 +08:00
|
|
|
|
|
2026-02-04 18:06:18 +08:00
|
|
|
|
public static Logger logger = LogManager.GetCurrentClassLogger();
|
2026-01-15 17:32:26 +08:00
|
|
|
|
private const string ip = "127.0.0.1";
|
|
|
|
|
|
private const string port = "6379";
|
|
|
|
|
|
static MyPublishRedis()
|
|
|
|
|
|
{
|
|
|
|
|
|
var redisHostStr = string.Format("{0}:{1}", ip, port);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(redisHostStr))
|
|
|
|
|
|
{
|
|
|
|
|
|
redis4 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=4");
|
2026-02-04 18:06:18 +08:00
|
|
|
|
redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6");
|
|
|
|
|
|
string channel = "__keyevent@6__:expired";
|
2026-01-15 17:32:26 +08:00
|
|
|
|
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
|
|
|
|
|
|
{
|
2026-02-04 18:06:18 +08:00
|
|
|
|
string data = msg.Body;
|
2026-01-15 17:32:26 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2026-02-04 18:06:18 +08:00
|
|
|
|
var data_take =redis4.Get(data);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(data_take))
|
|
|
|
|
|
{
|
|
|
|
|
|
var o = JsonConvert.DeserializeObject<OnOffLineData>(data_take);
|
|
|
|
|
|
o.CurrentStatus = "off";
|
|
|
|
|
|
string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
2026-01-15 17:32:26 +08:00
|
|
|
|
|
2026-02-04 18:06:18 +08:00
|
|
|
|
redis6.Publish("redis-on_off_line", str);
|
|
|
|
|
|
}
|
2026-01-15 17:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2026-02-04 18:06:18 +08:00
|
|
|
|
logger.Error("定阅出错:"+data);
|
2026-01-15 17:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-02-04 18:06:18 +08:00
|
|
|
|
redis6.Subscribe(QQQ);
|
2026-01-15 17:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|