In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to configure springboot redis cluster clusters". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to configure springboot redis cluster clusters".
The above code:
Import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.MapPropertySource; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate Import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;import com.gta.yyyf.commons.utils.SpringContextHolder;import redis.clients.jedis.JedisPoolConfig;import java.util.HashMap; import java.util.Map;@Configuration @ EnableCaching public class RedisClusterConfig extends CachingConfigurerSupport {private JedisPoolConfig poolConfig (int maxIdle, int maxTotal, long maxWaitMillis, boolean testOnBorrow, boolean testOnReturn) {JedisPoolConfig jedisPoolConfig = new JedisPoolConfig () JedisPoolConfig.setMaxIdle (maxIdle); jedisPoolConfig.setMaxTotal (maxTotal); jedisPoolConfig.setMaxWaitMillis (maxWaitMillis); jedisPoolConfig.setTestOnBorrow (testOnBorrow); jedisPoolConfig.setTestOnReturn (testOnReturn); return jedisPoolConfig;} private RedisClusterConfiguration redisCluterConfig (String clusterNodes) {Map source = new HashMap (); source.put ("spring.redis.cluster.nodes", clusterNodes); return new RedisClusterConfiguration (new MapPropertySource ("RedisClusterConfiguration", source)) } @ Bean (name = "redisConnectionFactory") public JedisConnectionFactory redisConnectionFactory (@ Value ("${spring.redis.cluster.maxIdle}") int maxIdle, @ Value ("${spring.redis.cluster.maxTotal}") int maxTotal, @ Value ("${spring.redis.cluster.maxWaitMillis}") long maxWaitMillis, @ Value ("${spring.redis.cluster.testOnBorrow}") boolean testOnBorrow @ Value ("${spring.redis.cluster.testOnReturn}") boolean testOnReturn, @ Value ("${spring.redis.cluster.nodes}") String clusterNodes, @ Value ("${spring.redis.cluster.password}") String password) {JedisConnectionFactory connectionFactory = new JedisConnectionFactory (redisCluterConfig (clusterNodes), poolConfig (maxIdle, maxTotal, maxWaitMillis, testOnBorrow, testOnReturn)) ConnectionFactory.setPassword (password); return connectionFactory;} @ Bean (name = "stringRedisCluterTemplate") public StringRedisTemplate stringRedisTemplate () {StringRedisTemplate template = new StringRedisTemplate (); JedisConnectionFactory jedisConnectionFactory = SpringContextHolder.getBean ("redisConnectionFactory"); template.setConnectionFactory (jedisConnectionFactory); return template;} @ Bean ("redisCluterTemplate") public RedisTemplate redisTemplate (JedisConnectionFactory factory) {RedisTemplate template = new RedisTemplate () Template.setConnectionFactory (factory); StringRedisSerializer keySerializer = new StringRedisSerializer (); GenericJackson2JsonRedisSerializer valueSerializer = new GenericJackson2JsonRedisSerializer (); template.setKeySerializer (keySerializer); template.setHashKeySerializer (keySerializer); template.setValueSerializer (valueSerializer); template.setHashValueSerializer (valueSerializer); template.afterPropertiesSet (); return template;} @ Bean public CacheManager cacheManager (RedisTemplate redisTemplate) {RedisCacheManager manager = new RedisCacheManager (redisTemplate) Manager.setDefaultExpiration (10); return manager }} configuration file: spring.redis.cluster.nodes=127.0.0.1:6379127.0.0.1:6380127.0.0.1:6381127.0.0.1:6379127.0.0.1:6380127.0.0.1:6381 spring.redis.cluster.timeout=2000 spring.redis.cluster.max-redirects=100 spring.redis.cluster.password=123456 spring.redis.cluster.maxIdle=200 spring.redis.cluster.maxTotal=1000 spring.redis.cluster.maxWaitMillis=2000 spring.redis.cluster.testOnBorrow=true spring.redis. Cluster.testOnReturn=truespring.redis.cluster.connectionTimeout=60000 spring.redis.cluster.soTimeout=2000 spring.redis.cluster.maxAttempts=5 has come here I believe that you have a deeper understanding of the "springboot redis cluster cluster configuration method", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.