最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Springboot2.X集成redis集群(Lettuce)連接的方法

 更新時(shí)間:2018年07月13日 13:39:54   作者:Damein_xym  
這篇文章主要介紹了Springboot2.X集成redis集群(Lettuce)連接的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

前提:搭建好redis集群環(huán)境,搭建方式請(qǐng)看:http://www.fzitv.net/article/143749.htm

1. 新建工程,pom.xml文件中添加redis支持

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2.配置application.properties

spring.redis.cluster.nodes=127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384,127.0.0.1:6385
spring.redis.cluster.timeout=1000
spring.redis.cluster.max-redirects=3

3.      新建下面的兩個(gè)類

@Configuration
public class RedisConfiguration {
  @Resource
  private LettuceConnectionFactory myLettuceConnectionFactory;
  @Bean
  public RedisTemplate<String, Serializable> redisTemplate() {
    RedisTemplate<String, Serializable> template = new RedisTemplate<>();
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    template.setConnectionFactory(myLettuceConnectionFactory);
    return template;
  }
} 
@Configuration
public class RedisFactoryConfig {
  @Autowired
  private Environment environment;
  @Bean
  public RedisConnectionFactory myLettuceConnectionFactory() {
    Map<String, Object> source = new HashMap<String, Object>();
    source.put("spring.redis.cluster.nodes", environment.getProperty("spring.redis.cluster.nodes"));
    source.put("spring.redis.cluster.timeout", environment.getProperty("spring.redis.cluster.timeout"));
    source.put("spring.redis.cluster.max-redirects", environment.getProperty("spring.redis.cluster.max-redirects"));
    RedisClusterConfiguration redisClusterConfiguration;
    redisClusterConfiguration = new RedisClusterConfiguration(new MapPropertySource("RedisClusterConfiguration", source));
    return new LettuceConnectionFactory(redisClusterConfiguration);
  }
} 

4. 執(zhí)行測(cè)試

@SpringBootTest
@RunWith(SpringRunner.class)
public class RedisConfigurationTest {

  @Autowired
private RedisTemplate redisTemplate;

@Test
public void redisTemplate() throws Exception {

    redisTemplate.opsForValue().set("author", "Damein_xym");
}

}

5. 驗(yàn)證,使用Redis Desktop Manager 連接redis節(jié)點(diǎn),查看里面的數(shù)據(jù)是否存在author,有如下顯示,證明成功。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

水城县| 石阡县| 宣恩县| 和龙市| 潼关县| 新和县| 中阳县| 大厂| 潼关县| 新闻| 康保县| 金湖县| 泊头市| 汽车| 梁平县| 怀化市| 鹿邑县| 黑龙江省| 罗城| 林周县| 泉州市| 老河口市| 溧阳市| 渝中区| 原平市| 揭东县| 文安县| 额尔古纳市| 德州市| 华阴市| 汉中市| 刚察县| 安阳县| 宁海县| 周口市| 霞浦县| 利川市| 涡阳县| 乌鲁木齐市| 峨眉山市| 三原县|