NewController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. using System.Threading;
  9. using Microsoft.AspNetCore.Mvc.RazorPages;
  10. using TencentCloud.Soe.V20180724.Models;
  11. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  12. using static Spire.Xls.Core.Spreadsheet.HTMLOptions;
  13. using System.Net.Http.Json;
  14. using System.Text.RegularExpressions;
  15. using System.Text;
  16. using TencentCloud.Oceanus.V20190422.Models;
  17. using System.Security.Cryptography;
  18. using YunhuiKit;
  19. using System.Diagnostics;
  20. namespace molilian.api.Controllers
  21. {
  22. [ApiController]
  23. [Route("[controller]/[action]")]
  24. public class NewController : ControllerBase
  25. {
  26. protected IHttpContextAccessor _accessor;
  27. public NewController(IHttpContextAccessor accessor)
  28. {
  29. _accessor = accessor;
  30. }
  31. [HttpGet]
  32. public async Task<ActionResult> redis()
  33. {
  34. var result = AlimamaPlus.GetFormattedObject("中国1@#阿斯蒂芬", "127.0.0.1", "0000-00-0000");
  35. string cacheKey = "tmp:test:case1";
  36. RedisHelper.Set(cacheKey, result, 300);
  37. var data1 = RedisHelper.Get<TkDataDTO>(cacheKey);
  38. var data2 = await RedisKit.GetAsync<TkDataDTO>(cacheKey);
  39. await RedisKit.SetAsync(cacheKey, result, 300);
  40. data1 = RedisHelper.Get<TkDataDTO>(cacheKey);
  41. data2 = await RedisKit.GetAsync<TkDataDTO>(cacheKey);
  42. await RedisKit.SetAsync(cacheKey, "a", 300);
  43. var data3 = RedisHelper.Get<int>(cacheKey);
  44. var data4 = await RedisKit.GetAsync<int>(cacheKey);
  45. return new APIResult(new { data = new List<TkDataDTO> { data1, data2 } });
  46. }
  47. [HttpGet]
  48. public async Task<ActionResult> redis2(int count = 100)
  49. {
  50. var stopwatch = new Stopwatch();
  51. stopwatch.Start();
  52. // 执行100次
  53. for (int i = 0; i < 100; i++)
  54. {
  55. int total_count = TkLogCore.GetTotal($":total:tb:2025-01-09");
  56. }
  57. stopwatch.Stop();
  58. var stopwatch2 = new Stopwatch();
  59. stopwatch2.Start();
  60. // 执行100次
  61. for (int i = 0; i < 100; i++)
  62. {
  63. int total_count = await TkLogCore.GetTotalAsync($":total:tb:2025-01-09");
  64. }
  65. stopwatch2.Stop();
  66. return new APIResult(new
  67. {
  68. ts = stopwatch.ElapsedMilliseconds,
  69. ts2 = stopwatch2.ElapsedMilliseconds,
  70. });
  71. }
  72. }
  73. }