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