RedisConfigInfo.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. namespace Lottomat.Cache.Redis
  7. {
  8. /// <summary>
  9. /// Redis配置
  10. /// </summary>
  11. public sealed class RedisConfigInfo : ConfigurationSection
  12. {
  13. public static RedisConfigInfo GetConfig()
  14. {
  15. RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("redisconfig");
  16. return section;
  17. }
  18. public static RedisConfigInfo GetConfig(string sectionName)
  19. {
  20. RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("redisconfig");
  21. if (section == null)
  22. throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
  23. return section;
  24. }
  25. /// <summary>
  26. /// 可写的Redis链接地址
  27. /// </summary>
  28. [ConfigurationProperty("WriteServerList", IsRequired = false)]
  29. public string WriteServerList
  30. {
  31. get
  32. {
  33. return (string)base["WriteServerList"];
  34. }
  35. set
  36. {
  37. base["WriteServerList"] = value;
  38. }
  39. }
  40. /// <summary>
  41. /// 可读的Redis链接地址
  42. /// </summary>
  43. [ConfigurationProperty("ReadServerList", IsRequired = false)]
  44. public string ReadServerList
  45. {
  46. get
  47. {
  48. return (string)base["ReadServerList"];
  49. }
  50. set
  51. {
  52. base["ReadServerList"] = value;
  53. }
  54. }
  55. /// <summary>
  56. /// 最大写链接数
  57. /// </summary>
  58. [ConfigurationProperty("MaxWritePoolSize", IsRequired = false, DefaultValue = 5)]
  59. public int MaxWritePoolSize
  60. {
  61. get
  62. {
  63. int maxWritePoolSize = (int)base["MaxWritePoolSize"];
  64. return maxWritePoolSize > 0 ? maxWritePoolSize : 5;
  65. }
  66. set
  67. {
  68. base["MaxWritePoolSize"] = value;
  69. }
  70. }
  71. /// <summary>
  72. /// 最大读链接数
  73. /// </summary>
  74. [ConfigurationProperty("MaxReadPoolSize", IsRequired = false, DefaultValue = 5)]
  75. public int MaxReadPoolSize
  76. {
  77. get
  78. {
  79. int maxReadPoolSize = (int)base["MaxReadPoolSize"];
  80. return maxReadPoolSize > 0 ? maxReadPoolSize : 5;
  81. }
  82. set
  83. {
  84. base["MaxReadPoolSize"] = value;
  85. }
  86. }
  87. /// <summary>
  88. /// 自动重启
  89. /// </summary>
  90. [ConfigurationProperty("AutoStart", IsRequired = false, DefaultValue = true)]
  91. public bool AutoStart
  92. {
  93. get
  94. {
  95. return (bool)base["AutoStart"];
  96. }
  97. set
  98. {
  99. base["AutoStart"] = value;
  100. }
  101. }
  102. /// <summary>
  103. /// 本地缓存到期时间,单位:秒
  104. /// </summary>
  105. [ConfigurationProperty("LocalCacheTime", IsRequired = false, DefaultValue = 36000)]
  106. public int LocalCacheTime
  107. {
  108. get
  109. {
  110. return (int)base["LocalCacheTime"];
  111. }
  112. set
  113. {
  114. base["LocalCacheTime"] = value;
  115. }
  116. }
  117. /// <summary>
  118. /// 是否记录日志,该设置仅用于排查redis运行时出现的问题,如redis工作正常,请关闭该项
  119. /// </summary>
  120. [ConfigurationProperty("RecordeLog", IsRequired = false, DefaultValue = false)]
  121. public bool RecordeLog
  122. {
  123. get
  124. {
  125. return (bool)base["RecordeLog"];
  126. }
  127. set
  128. {
  129. base["RecordeLog"] = value;
  130. }
  131. }
  132. }
  133. }