增加RCU上离线功能,能耗双通道
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using CommonTools;
|
||||
using CSRedis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using CSRedis;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
@@ -34,7 +35,38 @@ namespace Common
|
||||
redis4 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=4");
|
||||
//准备存储取电数据
|
||||
redis5 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=5");
|
||||
//Native subscribe
|
||||
string channel = "__keyevent@4__:expired";
|
||||
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
|
||||
{
|
||||
//string Key = CacheKey.UPGradeProgressBar + "_" + id;
|
||||
try
|
||||
{
|
||||
if (!msg.Body.StartsWith("hb#"))
|
||||
{
|
||||
bool containsHyphen = msg.Body.Contains("-");
|
||||
bool isNumeric = msg.Body.All(char.IsDigit);
|
||||
if (containsHyphen == false && isNumeric)
|
||||
{
|
||||
//string hotelcode = Tools.HostNumberToHotelCode(msg.Body).ToString();
|
||||
//OnOffLineData o = new OnOffLineData();
|
||||
//o.HotelCode = hotelcode;
|
||||
//o.HostNumber = msg.Body;
|
||||
//o.CurrentStatus = "off";
|
||||
//o.CurrentTime = DateTime.Now;
|
||||
////新来的数据
|
||||
//string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
||||
//CSRedisCacheHelper.redis3.Publish("redis-on_off_line", str);
|
||||
|
||||
//redis4.Set(HeartBeatPrefix + "_" + msg.Body, 1, 5 * 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
});
|
||||
redis.Subscribe(QQQ);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -62,7 +94,7 @@ namespace Common
|
||||
redis.Del(key);
|
||||
}
|
||||
|
||||
public static void Del_Partition(string key,int SliceNo=2)
|
||||
public static void Del_Partition(string key, int SliceNo = 2)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
client.Del(key);
|
||||
@@ -160,5 +192,111 @@ namespace Common
|
||||
{
|
||||
return redis.Ttl(key);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加Hash缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void HMSet(int SliceNo, string key, params object[] value)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
client.HMSet(key, value);
|
||||
}
|
||||
|
||||
public static void HMSet(int SliceNo, int ExpireTime_M, string key, params object[] value)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
client.HMSet(key, value);
|
||||
client.Expire(key, new TimeSpan(0, ExpireTime_M, 0));
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取Hash缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static T[] HMGet<T>(int SliceNo, string key, string KeyV)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
return client.HMGet<T>(key, KeyV);
|
||||
}
|
||||
public static Dictionary<string, string> HMGetAll(int SliceNo, string key)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
return client.HGetAll(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 某个hash值的数量
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetHMCount(string key)
|
||||
{
|
||||
return redis5.HGetAll(key).Count;
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除Hash缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static long HDelAll<T>(int SliceNo, string key)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
return client.HDel(key);
|
||||
}
|
||||
public static long HDel(int SliceNo, string key, string key1)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
return client.HDel(key, key1);
|
||||
}
|
||||
|
||||
public static void ListAdd(int SliceNo, string key, params object[] obj)
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
client.LPush(key, obj);
|
||||
}
|
||||
public static int MaxLen = 500000;
|
||||
public static void StreamAdd(int SliceNo, string key, string Value)
|
||||
{
|
||||
try
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
// 添加简单消息
|
||||
client.XAdd(key, MaxLen, "*", new ValueTuple<string, string>("__data", Value));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
public static void StreamConsume(int SliceNo, string key, string group = "UDPData", string consumer = "Crics1")
|
||||
{
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
|
||||
var data = redis.XReadGroup(group, consumer, 100, 10, new ValueTuple<string, string>(key, ">"));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
//检查pending表的长度
|
||||
//消费确认前,pending 应该等于2
|
||||
var pending = redis.XPending(key, group);
|
||||
foreach (var item in data)
|
||||
{
|
||||
var idarray = item.Item2;
|
||||
foreach (var SerializeNo in idarray)
|
||||
{
|
||||
var id1 = SerializeNo.Item1;
|
||||
redis.XAck(key, group, id1);
|
||||
redis.XDel(key, id1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,6 +572,14 @@ namespace CommonTools
|
||||
long unixTimestampMillisecondsManual = (long)(DateTime.UtcNow - unixEpoch).TotalSeconds;
|
||||
return unixTimestampMillisecondsManual;
|
||||
}
|
||||
public static long GetUnixTime_MS()
|
||||
{
|
||||
//DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
//double unixTimestampMillisecondsManual = (DateTime.UtcNow - unixEpoch).TotalMilliseconds;
|
||||
//return unixTimestampMillisecondsManual;
|
||||
|
||||
return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); // 返回 long
|
||||
}
|
||||
public static DateTime GetTimeFromUnixTime(long timestampSeconds)
|
||||
{
|
||||
// Unix 时间戳的起始时间(1970-01-01 00:00:00 UTC)
|
||||
|
||||
Reference in New Issue
Block a user