摘要: public async Task<string> Wait3S() { await Task.Delay(3000); Console.WriteLine("Wait 3 S"); return ""; } #region 异步任务-状态机 #if true TestClass testClass 阅读全文
posted @ 2024-08-20 23:04 DaiWK 阅读(20) 评论(0) 推荐(1) 编辑
摘要: 服务端测试代码 静态类 public class StaticClass { public static int Count = 0; public static int SafeCount = 0; public static int GetCount() { return Count++; } 阅读全文
posted @ 2024-08-19 00:39 DaiWK 阅读(6) 评论(0) 推荐(1) 编辑
摘要: 冒泡排序 // 冒泡排序加去重 public static int[] DistinctAndOrder(int[] OldArray) { if (OldArray != null && OldArray.Length > 0) { //排序 for (int i = 0; i < OldArra 阅读全文
posted @ 2024-08-09 00:04 DaiWK 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 一、单一职责、命名规范遵循restful 二、接口安全 参数校验 接口鉴权 敏感数据脱敏、加密 防重复提交(前端控制、时间戳、接口幂等性) 数据防篡改(签名) 阅读全文
posted @ 2024-08-08 23:50 DaiWK 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 一、Nuget引入 StackExchange.Redis、DistributedLock.Redis依赖 二、使用 StackExchange.Redis 对redis操作做简单封装 public class RedisHelper { private static ConnectionMulti 阅读全文
posted @ 2024-08-05 16:12 DaiWK 阅读(12) 评论(0) 推荐(1) 编辑
摘要: 晚上睡不着,脑子里总想着一些问题,试着写一写对于SQL查询优化的见解。 首先,数据库有自己的查询优化器,执行一条查询SQL优化器会选择最优的方式(不走索引、走索引、走哪个索引), 所以索引不是越多越好,因为创建索引需要成本,提高索引命中率是优化SQL的关键。 索引分为主键索引和普通索引,在Mysql 阅读全文
posted @ 2024-08-01 03:33 DaiWK 阅读(7) 评论(0) 推荐(2) 编辑
摘要: //自定义异常 public class MyException : Exception { public MyException(string? message) : base(message) { } } public class CircuitBreakerExample { //熔断规则 p 阅读全文
posted @ 2024-07-31 10:39 DaiWK 阅读(3) 评论(0) 推荐(1) 编辑
摘要: 中间件定义 /// <summary> /// 自定义中间件1 /// </summary> public class MyMiddleware : IMiddleware { public async Task InvokeAsync(HttpContext context, RequestDel 阅读全文
posted @ 2024-07-16 23:34 DaiWK 阅读(8) 评论(0) 推荐(1) 编辑
摘要: 利用特性Attribute+反射+代理类实现AOP 一、定义自定义特性 /// <summary> /// 自定义特性,方法执行前调用 /// </summary> public class CustomBeforeAttribute : Attribute { } /// <summary> // 阅读全文
posted @ 2024-07-15 09:42 DaiWK 阅读(4) 评论(0) 推荐(1) 编辑
摘要: //实体类定义 public class User { public int Id { get; set; } public string Name { get; set; } } public class UserIncome { public int Id { get; set; } publi 阅读全文
posted @ 2024-07-11 00:51 DaiWK 阅读(2) 评论(0) 推荐(0) 编辑