Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RedisConfig.cs 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Text;
  3. namespace HealthMonitor.Model.Config
  4. {
  5. /// <summary>
  6. /// Redis配置模板类
  7. /// </summary>
  8. public class RedisConfig
  9. {
  10. public string Server { get; set; } = string.Empty;
  11. /// <summary>
  12. /// Redis server password
  13. /// </summary>
  14. public string Password { get; set; } = string.Empty;
  15. /// <summary>
  16. /// Redis server database, default 0
  17. /// </summary>
  18. public int? DefaultDatabase { get; set; }
  19. /// <summary>
  20. /// The asynchronous method automatically uses pipeline, and the 10W concurrent time is 450ms(welcome to feedback)
  21. /// </summary>
  22. public bool? AsyncPipeline { get; set; }
  23. /// <summary>
  24. /// Connection pool size, default 50
  25. /// </summary>
  26. public int? Poolsize { get; set; }
  27. /// <summary>
  28. /// Idle time of elements in the connection pool(MS), suitable for connecting to remote redis server, default 20000
  29. /// </summary>
  30. public int? IdleTimeout { get; set; }
  31. /// <summary>
  32. /// Connection timeout(MS), default 5000
  33. /// </summary>
  34. public int? ConnectTimeout { get; set; }
  35. /// <summary>
  36. /// Send / receive timeout(MS), default 10000
  37. /// </summary>
  38. public int? SyncTimeout { get; set; }
  39. /// <summary>
  40. /// Preheat connections, receive values such as preheat = 5 preheat 5 connections, default 5
  41. /// </summary>
  42. public int? Preheat { get; set; }
  43. /// <summary>
  44. /// Follow system exit event to release automatically, default true
  45. /// </summary>
  46. public bool? AutoDispose { get; set; }
  47. /// <summary>
  48. /// Enable encrypted transmission, default false
  49. /// </summary>
  50. public bool? Ssl { get; set; }
  51. /// <summary>
  52. /// 是否尝试集群模式,阿里云、腾讯云集群需要设置此选项为 false, default true
  53. /// </summary>
  54. public bool? Testcluster { get; set; }
  55. /// <summary>
  56. /// Execution error, retry attempts, default 0
  57. /// </summary>
  58. public int? Tryit { get; set; }
  59. /// <summary>
  60. /// Connection name, use client list command to view
  61. /// </summary>
  62. public string? Name { get; set; }
  63. /// <summary>
  64. /// key前辍,所有方法都会附带此前辍,csredis.Set(prefix + "key", 111)
  65. /// </summary>
  66. public string? Prefix { get; set; }
  67. public override string ToString()
  68. {
  69. if (string.IsNullOrWhiteSpace(Server)) throw new ArgumentNullException(nameof(Server));
  70. var sb = new StringBuilder(Server);
  71. if (!string.IsNullOrWhiteSpace(Password)) sb.Append($",password={Password}");
  72. if (DefaultDatabase.HasValue) sb.Append($",defaultDatabase={DefaultDatabase}");
  73. if (AsyncPipeline.HasValue) sb.Append($",asyncPipeline={AsyncPipeline}");
  74. if (Poolsize.HasValue) sb.Append($",poolsize={Poolsize}");
  75. if (IdleTimeout.HasValue) sb.Append($",idleTimeout={IdleTimeout}");
  76. if (ConnectTimeout.HasValue) sb.Append($",connectTimeout={ConnectTimeout}");
  77. if (SyncTimeout.HasValue) sb.Append($",syncTimeout={0}");
  78. if (Preheat.HasValue) sb.Append($",preheat={Preheat}");
  79. if (AutoDispose.HasValue) sb.Append($",autoDispose={AutoDispose}");
  80. if (Ssl.HasValue) sb.Append($",ssl={Ssl}");
  81. if (Testcluster.HasValue) sb.Append($",testcluster={Testcluster}");
  82. if (Tryit.HasValue) sb.Append($",tryit={Tryit}");
  83. if (!string.IsNullOrWhiteSpace(Name)) sb.Append($",name={Name}");
  84. if (!string.IsNullOrWhiteSpace(Prefix)) sb.Append($",prefix={Prefix}");
  85. return sb.ToString();
  86. }
  87. }
  88. }