In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "spring boot integration of redisson methods", detailed content, clear steps, details handled properly, I hope that this "spring boot integration of redisson methods" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
Preface
In this article, if you know spring boot and practice it, non-spring boot users can skip it or take a look at it.
Redisson is the java client program of redis, which is used by many companies at home and abroad, as follows
There are also many official examples in the integration with spring, which is more convenient.
Integrate jedis instance, jarredis.clientsjedis2.9.0org.apache.commonscommons-pool22.2spring bean configuration xml integrated redisson instance referenced before xml integration, and jar introduced before java bean integration
Org.redisson
Redisson
2.5.0
Javabean is configured as follows / * Created by kl on 2016-10-21. * / @ Configuration@ComponentScanpublic class RedsissonConfig {@ Bean (destroyMethod= "shutdown") RedissonClient redisson (@ Value ("classpath:/conf/redisson.yaml") Resource configFile) throws IOException {Config config = Config.fromYAML (configFile.getInputStream ()); return Redisson.create (config);}}
Spring integrates redis client jedis and redisson, and can provide yaml,json configuration file to instantiate redissonClient or use spring xml to configure. Redisson officially gives tags such as spring boot to simplify the configuration in xml, but if our program is spring boot, we usually use application.properties to configure our application configuration parameters. We do not want to provide additional configuration files such as yaml,json,xml, although spring boot also supports this. So how to configure redisson using application.properties, see below?
Provide instantiation of javabean/** * Created by kl on 2017-09-26. * redisson client configuration * / @ ConfigurationProperties (prefix = "spring.redisson") @ Configurationpublic class RedissonConfig {private String address; private int connectionMinimumIdleSize = 10; private int idleConnectionTimeout=10000; private int pingTimeout=1000; private int connectTimeout=10000; private int timeout=3000; private int retryAttempts=3; private int retryInterval=1500; private int reconnectionTimeout=3000; private int failedAttempts=3; private String password = null; private int subscriptionsPerConnection=5; private String clientName=null; private int subscriptionConnectionMinimumIdleSize = 1; private int subscriptionConnectionPoolSize = 50; private int connectionPoolSize = 64 Private int database = 0; private boolean dnsMonitoring = false; private int dnsMonitoringInterval = 5000; private int thread; / / current number of processed cores * 2 private String codec= "org.redisson.codec.JsonJacksonCodec"; @ Bean (destroyMethod = "shutdown") RedissonClient redisson () throws Exception {Config config = new Config () Config.useSingleServer (). SetAddress (address) .setConnectionMinimumIdleSize (connectionMinimumIdleSize) .setConnectionPoolSize (connectionPoolSize) .setDatabase (database) .setDnsMonitoring (dnsMonitoring) .setDnsMonitoringInterval (dnsMonitoringInterval) .setSubscriptionConnectionMinimumIdleSize (subscriptionConnectionMinimumIdleSize) .setSubscriptionConnectionPoolSize (subscriptionConnectionPoolSize). SetSubscriptionsPerConnection (subscriptionsPerConnection) .setClientName (clientName) .setFailedAttempts (failedAttempts) .setRetryAttempts (retryAttempts) .setRetryInterval (retryInterval) .setReconnectionTimeout (reconnectionTimeout) .setTimeout (timeout) .setC onnectTimeout (connectTimeout) .setIdleConnectionTimeout (idleConnectionTimeout) .setPingTimeout (pingTimeout) .setPassword (password) Codec codec= (Codec) ClassUtils.forName (getCodec (), ClassUtils.getDefaultClassLoader ()). NewInstance (); config.setCodec (codec); config.setThreads (thread); config.setEventLoopGroup (new NioEventLoopGroup ()); config.setUseLinuxNativeEpoll (false); return Redisson.create (config);}
Note: the above code is not complete, omitting the get set code
Application.properties add the following configuration # redis link address spring.redisson.address=192.168.1.204:6379# current number of processing cores * 2spring.redisson.thread=4# specifies the minimum number of idle connections for codec spring.redisson.codec=org.redisson.codec.JsonJacksonCodec;#. Default: 10, minimum number of persistent connections (persistent connections) spring.redisson.connectionMinimumIdleSize=12# connection idle timeout, unit: millisecond default 10000 The number of connections in the current connection pool exceeds the minimum number of idle connections. # and the connection idle time exceeds this value. These connections will be automatically closed and the spring.redisson.idleConnectionTimeout=10000#ping node timeout will be removed from the connection pool. Unit: millisecond. Default 1000spring.redisson.pingTimeout=1000# connection wait timeout, unit: millisecond. Default 10000spring.redisson.connectTimeout=10000# command wait timeout, unit: millisecond. Default is 3000. The time to wait for the node to reply to the command. This time starts to count the number of failed retries of the spring.redisson.timeout=3000# command when the command is sent successfully. Default value: 3spring.redisson.retryAttempts=2# command retry sending interval (in milliseconds), default value: 1500spring.redisson.retryInterval=1500# reconnection interval, unit: millisecond, default value: 3000; when the connection is disconnected, the maximum number of times spring.redisson.reconnectionTimeout=3000# fails to wait for the connection to be reestablished. The default value is 3 Try again after the failure until the reconnectionTimeout times out. Spring.redisson.failedAttempts=2# authentication password # spring.redisson.password=# maximum number of subscriptions for a single connection. Default: 5spring.redisson.subscriptionsPerConnection=5# client name # minimum number of idle connections for publish and subscribe connections. Default: 1Redisson often implements many functions through publishing and subscribing internally. # the size of spring.redisson.subscriptionConnectionMinimumIdleSize=1# publish and subscribe connection pool is required to maintain a certain number of publish / subscribe connections for a long time. Default is the maximum capacity of 50spring.redisson.subscriptionConnectionPoolSize=50# connection pool. Default: 64; the number of connections in the connection pool automatically scales the spring.redisson.connectionPoolSize=64# database number. Default: whether 0spring.redisson.database=0# enables DNS monitoring. Default: falsespring.redisson.dnsMonitoring=false#DNS monitoring interval (in milliseconds). Default: 5000spring.redisson.dnsMonitoringInterval=5000.
Java bean has written the official default initial value for all the values that need to be configured. If you do not consider changing the default value, you only need to add the following configuration to your application.properties.
# redis Link address spring.redisson.address=192.168.1.204:6379
Note: the connection mode is configured in stand-alone mode. If you want to configure cluster mode and sentinel mode in this way, please refer to the official wiki and modify the java bean.
After reading this, the article "the method of spring boot integrating redisson" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.