12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
建站问答 时间:2024-11-30 20:02:07
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
要配置Spring Boot使用Redis哨兵模式,需要进行以下步骤:添加Redis和哨兵的依赖:在pom.xml文件中添加以下依赖:<dependency><groupId>org.springframework.boot</groupId><artifa
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
要配置Spring Boot使用Redis哨兵模式,需要进行以下步骤:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency>
spring.redis.sentinel.master=masterspring.redis.sentinel.nodes=127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381
@Configurationpublic class RedisConfig {@Beanpublic JedisConnectionFactory jedisConnectionFactory() {RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration().master("master").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380).sentinel("127.0.0.1", 26381);return new JedisConnectionFactory(sentinelConfig);}@Beanpublic RedisTemplate<String, Object> redisTemplate() {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setConnectionFactory(jedisConnectionFactory());template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new GenericJackson2JsonRedisSerializer());return template;}}
@Autowiredprivate RedisTemplate<String, Object> redisTemplate;public void setValue(String key, Object value) {redisTemplate.opsForValue().set(key, value);}public Object getValue(String key) {return redisTemplate.opsForValue().get(key);}
通过以上步骤,就可以在Spring Boot中配置和使用Redis哨兵模式了。
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19