
- 1.public static bool SpanLimit(string key, long seconds)
- {
- string redisKey = $"{key}_redis";
- if (Redis.StringHelper.StringSetIfNotExists<int>(redisKey, 1))
- {
- Redis.KeyHelper.KeyExpire(redisKey, TimeSpan.FromSeconds(seconds));
- return false;
- }
- else
- {
- return true;
- }
- }
- 2.日调用次数限制
- public static bool CallDayTimesLimit(string key, int limitCount)
- {
- key = $"{key}_{DateTime.Now.ToString("yy-MM-dd")}";
- int count = CommonService.Redis.StringHelper.StringGet<int>(key);
- if (count > limitCount)
- {
- return true;
- }
- count = count + 1;
- CommonService.Redis.StringHelper.StringSet<int>(key, count, CommonHelper.GetDayTimeLeft().Add(TimeSpan.FromMinutes(10)));
- return false;
- }
- 3.获取日调用次数限制
- public static int GetDayTimesLimit(string key)
- {
- key = $"{key}_{DateTime.Now.ToString("yy-MM-dd")}";
- int count = CommonService.Redis.StringHelper.StringGet<int>(key);
- return count;
- }
- public static int SubTimes(string key, int num = 1)
- {
- key = $"{key}_{DateTime.Now.ToString("yy-MM-dd")}";
- int count = CommonService.Redis.StringHelper.StringGet<int>(key);
- count = count - num;
- CommonService.Redis.StringHelper.StringSet<int>(key, count, CommonHelper.GetDayTimeLeft().Add(TimeSpan.FromMinutes(10)));
- return count;
- }
- public static int AddTimes(string key, int num = 1)
- {
- key = $"{key}_{DateTime.Now.ToString("yy-MM-dd")}";
- int count = CommonService.Redis.StringHelper.StringGet<int>(key);
- count = count + num;
- CommonService.Redis.StringHelper.StringSet<int>(key, count, CommonHelper.GetDayTimeLeft().Add(TimeSpan.FromMinutes(10)));
- return count;
- }
评价
排名
11
文章
201
粉丝
10
评论
13
EF连接MySQL连接MySQL数据库操作中文数据乱码解决方法
剑轩 :
准确点应该是ef连接mysql
Layui插件上传图片具体步奏以及获取图片地址
风清月 : 厉害老!
Action与Func的用法-----委托
剑轩 : 可以可以
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术