万佳安设备数据
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RedisConfig.cs 3.8KB

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