From a247547df86f0fad8f03aebb91de68d3f2bc7918 Mon Sep 17 00:00:00 2001 From: 移动系统liao <liaoxujun@qq.com> Date: 星期四, 01 五月 2025 10:16:52 +0800 Subject: [PATCH] 修正sugsql导航更新加配置的bug --- cylsg/cylsg.redis/EzCoreNetRedisService.cs | 82 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 78 insertions(+), 4 deletions(-) diff --git a/cylsg/cylsg.redis/EzCoreNetRedisService.cs b/cylsg/cylsg.redis/EzCoreNetRedisService.cs index ba679b1..f81b0a7 100644 --- a/cylsg/cylsg.redis/EzCoreNetRedisService.cs +++ b/cylsg/cylsg.redis/EzCoreNetRedisService.cs @@ -1,5 +1,6 @@ 锘縰sing Furion; using Furion.DependencyInjection; +using Microsoft.AspNetCore.DataProtection.KeyManagement; using SqlSugar; using System; using System.Collections.Generic; @@ -9,7 +10,7 @@ namespace EzCoreNet.Redis { - public class EzCoreNetRedisService : IEzCoreNetRedisService,IScoped + public class EzCoreNetRedisService : IEzCoreNetRedisService, IScoped { public bool Add(string key, object value, int expireSeconds) { @@ -34,9 +35,9 @@ return RedisHelper.Ttl(key); } - public bool SetTtl(string key, int ttl) + public bool SetTtl(string key, int ttl) { - return RedisHelper.Expire(key, ttl); + return RedisHelper.Expire(key, ttl); } /// <summary> @@ -69,7 +70,7 @@ { return RedisHelper.Keys(Prefix + "*"); } - + /// <summary> /// 鍚庡幓涓�涓紦瀛橈紝濡傛灉娌℃湁锛屽垯浠庢暟鎹簱涓幏鍙栵紝 /// </summary> @@ -99,6 +100,79 @@ return Data; } + public long Incrby(string key) + { + return RedisHelper.IncrBy(key); + } + + public string Get32sn() + { + string formattedDate = DateTime.Now.ToString("yyyyMMdd"); + + + var sn = Incrby($"CreatSnKey:{formattedDate}"); + if (sn < 1) + { + //璁剧疆鏈夋晥鏈熼檺涓�24灏忔椂 + SetTtl($"CreatSnKey:{formattedDate}", 24 * 60 * 60); + } + string re = "EZCoreCanYinLingShiGon" + formattedDate + sn.ToString(); + + return re; + } + + public string GetYYYMMddAnd4sn() + { + string formattedDate = DateTime.Now.ToString("yyyyMMdd"); + + + var sn = Incrby($"CreatYYYMMddAnd4snKey:{formattedDate}"); + if (sn < 1) + { + //璁剧疆鏈夋晥鏈熼檺涓�24灏忔椂 + SetTtl($"CreatYYYMMddAnd4snKey:{formattedDate}", 24 * 60 * 60); + } + string re = formattedDate + sn.ToString("D4"); + + return re; + } + /// <summary> + /// + /// </summary> + /// <param name="LockKey"></param> + /// <param name="expireSeconds"></param> + /// <param name="value"></param> + /// <returns></returns> + + public async Task<bool> TryLock(string LockKey, int expireSeconds = 600, string value = "Lock") + { + if (await RedisHelper.SetNxAsync(LockKey, value) == true) + { + if( await RedisHelper.ExpireAsync(LockKey, expireSeconds)==false) + return false; + return true; + } + else + return false; + + + } + + + /// <summary> + /// + /// </summary> + /// <param name="LockKey"></param> + /// <returns></returns> + public async Task<bool > TryUnLock(string LockKey) + { + var b= await RedisHelper.DelAsync(LockKey); + if(b>0) + return true; + else + return false; + + } } } -- Gitblit v1.9.1