大数据互联网架构阶段 Redis(二)
生活随笔
收集整理的這篇文章主要介紹了
大数据互联网架构阶段 Redis(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Redis(二)
零 、 目錄
- 將緩存引入電商項目
- 主從復制
- 哨兵模式
- 集群容忍度
- CAP理論
十、 將緩存引入電商項目
使用Spring框架維護Jedis池對象
引入一個配置文件 application-redis.config
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- 構建連接池配置信息 --><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"><!-- 最大連接數 --><property name="maxTotal" value="${redis.maxTotal}" /></bean><bean id="jedisShardInfo1" class="redis.clients.jedis.JedisShardInfo"><constructor-arg index="0" value="${redis.node1.ip}" /><constructor-arg index="1" value="${redis.node1.port}"type="int" /></bean><!-- bean id="jedisShardInfo2" class="redis.clients.jedis.JedisShardInfo"><constructor-arg index="0" value="${redis.node2.ip}" /><constructor-arg index="1" value="${redis.node2.port}"type="int" /></bean><bean id="jedisShardInfo3" class="redis.clients.jedis.JedisShardInfo"><constructor-arg index="0" value="${redis.node3.ip}" /><constructor-arg index="1" value="${redis.node3.port}"type="int" /></bean--><!-- 定義集群連接池 --><bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"destroy-method="close"><constructor-arg index="0" ref="jedisPoolConfig" /><constructor-arg index="1"><list><ref bean="jedisShardInfo1" /><!--ref bean="jedisShardInfo2" /><ref bean="jedisShardInfo3" /--></list></constructor-arg></bean></beans>需要加載配置文件 , 在application.xml(Spring核心配置文件中配置加載application-redis.xml中所需要的配置信息)
redis.maxTotal=200 redis.node1.ip=106.75.85.179 redis.node1.port=6379 redis.node2.ip=106.75.85.179 redis.node2.port=6380 redis.node3.ip=106.75.85.179 redis.node3.port=6381使用注解自動注入shardedjedidpool對象 , 即可使用 。
十一、 主從復制
十二、 哨兵模式
十三、 集群容忍度:
選舉過半原則導致 , 集群容忍度概念的引出
2個哨兵,多少算過半(2個)--,允許宕機的個數0,集群容忍度0, 3個哨兵,2個過半沒允許,宕機的個數是1,容忍度1 4個哨兵,3個過半,宕機個數允許1,容忍度1 2n個選舉法人,2n-1個選舉法人的容忍度一樣十二、 CAP理論
問題: 使用Jedis連接之前是否需要先打開redis客戶端?
總結
以上是生活随笔為你收集整理的大数据互联网架构阶段 Redis(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据 互联网架构阶段 Nginx的使
- 下一篇: 大数据 互联网架构阶段 Redis(三)