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

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

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

前提:搭建好redis集群環(huán)境,搭建方式請看:http://m.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.      新建下面的兩個類

@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í)行測試

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

  @Autowired
private RedisTemplate redisTemplate;

@Test
public void redisTemplate() throws Exception {

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

}

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

云林县| 讷河市| 富源县| 桦甸市| 十堰市| 巴南区| 信阳市| 台前县| 宾川县| 易门县| 宁阳县| 塔城市| 嘉禾县| 铜陵市| 定边县| 荥经县| 五大连池市| 河曲县| 孟村| 武鸣县| 巢湖市| 阜平县| 上思县| 句容市| 清远市| 阜新| 台山市| 加查县| 康保县| 东宁县| 仁怀市| 扶风县| 手机| 镇宁| 敖汉旗| 文水县| 额济纳旗| 鹰潭市| 万安县| 九龙坡区| 南丹县|