RedissonConfig.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package cn.keking.config;
  2. import io.netty.channel.nio.NioEventLoopGroup;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.redisson.client.codec.Codec;
  5. import org.redisson.config.Config;
  6. import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
  7. import org.springframework.boot.context.properties.ConfigurationProperties;
  8. import org.springframework.context.annotation.Bean;
  9. import org.springframework.context.annotation.Configuration;
  10. import org.springframework.util.ClassUtils;
  11. /**
  12. * Created by kl on 2017/09/26.
  13. * redisson 客户端配置
  14. */
  15. @ConditionalOnExpression("'${cache.type:default}'.equals('redis')")
  16. @ConfigurationProperties(prefix = "spring.redisson")
  17. @Configuration
  18. public class RedissonConfig {
  19. private String address;
  20. private int connectionMinimumIdleSize = 10;
  21. private int idleConnectionTimeout=10000;
  22. private int pingTimeout=1000;
  23. private int connectTimeout=10000;
  24. private int timeout=3000;
  25. private int retryAttempts=3;
  26. private int retryInterval=1500;
  27. private int reconnectionTimeout=3000;
  28. private int failedAttempts=3;
  29. private String password = null;
  30. private int subscriptionsPerConnection=5;
  31. private String clientName=null;
  32. private int subscriptionConnectionMinimumIdleSize = 1;
  33. private int subscriptionConnectionPoolSize = 50;
  34. private int connectionPoolSize = 64;
  35. private int database = 0;
  36. private boolean dnsMonitoring = false;
  37. private int dnsMonitoringInterval = 5000;
  38. private int thread; //当前处理核数量 * 2
  39. private String codec="org.redisson.codec.JsonJacksonCodec";
  40. @Bean
  41. Config config() throws Exception {
  42. Config config = new Config();
  43. config.useSingleServer().setAddress(address)
  44. .setConnectionMinimumIdleSize(connectionMinimumIdleSize)
  45. .setConnectionPoolSize(connectionPoolSize)
  46. .setDatabase(database)
  47. .setDnsMonitoring(dnsMonitoring)
  48. .setDnsMonitoringInterval(dnsMonitoringInterval)
  49. .setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
  50. .setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
  51. .setSubscriptionsPerConnection(subscriptionsPerConnection)
  52. .setClientName(clientName)
  53. .setFailedAttempts(failedAttempts)
  54. .setRetryAttempts(retryAttempts)
  55. .setRetryInterval(retryInterval)
  56. .setReconnectionTimeout(reconnectionTimeout)
  57. .setTimeout(timeout)
  58. .setConnectTimeout(connectTimeout)
  59. .setIdleConnectionTimeout(idleConnectionTimeout)
  60. .setPingTimeout(pingTimeout)
  61. .setPassword(StringUtils.trimToNull(password));
  62. Codec codec=(Codec) ClassUtils.forName(getCodec(), ClassUtils.getDefaultClassLoader()).newInstance();
  63. config.setCodec(codec);
  64. config.setThreads(thread);
  65. config.setEventLoopGroup(new NioEventLoopGroup());
  66. config.setUseLinuxNativeEpoll(false);
  67. return config;
  68. }
  69. public int getThread() {
  70. return thread;
  71. }
  72. public void setThread(int thread) {
  73. this.thread = thread;
  74. }
  75. public String getAddress() {
  76. return address;
  77. }
  78. public void setAddress(String address) {
  79. this.address = address;
  80. }
  81. public int getIdleConnectionTimeout() {
  82. return idleConnectionTimeout;
  83. }
  84. public void setIdleConnectionTimeout(int idleConnectionTimeout) {
  85. this.idleConnectionTimeout = idleConnectionTimeout;
  86. }
  87. public int getPingTimeout() {
  88. return pingTimeout;
  89. }
  90. public void setPingTimeout(int pingTimeout) {
  91. this.pingTimeout = pingTimeout;
  92. }
  93. public int getConnectTimeout() {
  94. return connectTimeout;
  95. }
  96. public void setConnectTimeout(int connectTimeout) {
  97. this.connectTimeout = connectTimeout;
  98. }
  99. public int getTimeout() {
  100. return timeout;
  101. }
  102. public void setTimeout(int timeout) {
  103. this.timeout = timeout;
  104. }
  105. public int getRetryAttempts() {
  106. return retryAttempts;
  107. }
  108. public void setRetryAttempts(int retryAttempts) {
  109. this.retryAttempts = retryAttempts;
  110. }
  111. public int getRetryInterval() {
  112. return retryInterval;
  113. }
  114. public void setRetryInterval(int retryInterval) {
  115. this.retryInterval = retryInterval;
  116. }
  117. public int getReconnectionTimeout() {
  118. return reconnectionTimeout;
  119. }
  120. public void setReconnectionTimeout(int reconnectionTimeout) {
  121. this.reconnectionTimeout = reconnectionTimeout;
  122. }
  123. public int getFailedAttempts() {
  124. return failedAttempts;
  125. }
  126. public void setFailedAttempts(int failedAttempts) {
  127. this.failedAttempts = failedAttempts;
  128. }
  129. public String getPassword() {
  130. return password;
  131. }
  132. public void setPassword(String password) {
  133. this.password = password;
  134. }
  135. public int getSubscriptionsPerConnection() {
  136. return subscriptionsPerConnection;
  137. }
  138. public void setSubscriptionsPerConnection(int subscriptionsPerConnection) {
  139. this.subscriptionsPerConnection = subscriptionsPerConnection;
  140. }
  141. public String getClientName() {
  142. return clientName;
  143. }
  144. public void setClientName(String clientName) {
  145. this.clientName = clientName;
  146. }
  147. public int getSubscriptionConnectionMinimumIdleSize() {
  148. return subscriptionConnectionMinimumIdleSize;
  149. }
  150. public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) {
  151. this.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize;
  152. }
  153. public int getSubscriptionConnectionPoolSize() {
  154. return subscriptionConnectionPoolSize;
  155. }
  156. public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) {
  157. this.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize;
  158. }
  159. public int getConnectionMinimumIdleSize() {
  160. return connectionMinimumIdleSize;
  161. }
  162. public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) {
  163. this.connectionMinimumIdleSize = connectionMinimumIdleSize;
  164. }
  165. public int getConnectionPoolSize() {
  166. return connectionPoolSize;
  167. }
  168. public void setConnectionPoolSize(int connectionPoolSize) {
  169. this.connectionPoolSize = connectionPoolSize;
  170. }
  171. public int getDatabase() {
  172. return database;
  173. }
  174. public void setDatabase(int database) {
  175. this.database = database;
  176. }
  177. public boolean isDnsMonitoring() {
  178. return dnsMonitoring;
  179. }
  180. public void setDnsMonitoring(boolean dnsMonitoring) {
  181. this.dnsMonitoring = dnsMonitoring;
  182. }
  183. public int getDnsMonitoringInterval() {
  184. return dnsMonitoringInterval;
  185. }
  186. public void setDnsMonitoringInterval(int dnsMonitoringInterval) {
  187. this.dnsMonitoringInterval = dnsMonitoringInterval;
  188. }
  189. public String getCodec() {
  190. return codec;
  191. }
  192. public void setCodec(String codec) {
  193. this.codec = codec;
  194. }
  195. }