转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/147.html

nfinispan 8 包含了一个新的在 Redis k/v 服务器中存储缓存数据的 cache store。这个 cache store 可以把缓存数据存储在一个集中的 Redis 中,所有的 Infinispan 客户端都可以访问。

Cache store 支持三种 Redis 的部署方式:单服务器、主从切换(Sentinel)和集群(需要 Redis 3 支持)。目前支持的 Redis 版本包括 2.8+ 和 3.0+。

数据过期和清理由 Redis 负责,可以减轻 Infinispan 服务器人工删除 cache 项的工作量。

拓扑结构

独立服务器

对于单服务器部署,cache store 会指向所连的 Redis 的 master,将其作为数据的存储。使用这种结构,Redis 是没有容灾功能的,除非在它上面另外再自己构造一个。下面是独立服务器的本地cache store 的配置:

<?xml version="1.0" encoding="UTF-8"?>
<infinispan
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd              urn:infinispan:config:store:redis:8.0 
http://www.infinispan.org/schemas/infinispan-cachestore-redis-config-8.0.xsd"
    xmlns="urn:infinispan:config:8.0"
    xmlns:redis="urn:infinispan:config:store:redis:8.0" >     <cache-container>
        <local-cache>
            <persistence passivation="false">
                <redis-store xmlns="urn:infinispan:config:store:redis:8.0"
                    topology="server" socket-timeout="10000" connection-timeout="10000">
                    <redis-server host="server1" />        <connection-pool min-idle="6" max-idle="10" max-total="20" 
min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
                </redis-store>
            </persistence>
        </local-cache>
    </cache-container>
</infinispan>#p#分页标题#e#

注意 topology 属性在这里是 server。这可以保证 cache store 使用的是独立的 Redis 服务器拓扑结构。只需要定义一个 Redis 服务器(如果定义了多个,只有第一个会被使用),端口会使用 Redis 的默认端口 6379,也可以使用 port 属性覆盖端口。所有的连接由一个连接池进行管理,连接池同时还负责连接的创建、释放、选择处于空闲的连接。

Sentinel模式

Sentinel 模式依赖于 Redis 的 Sentinel 服务器,以此来连接到 Redis 的 master。具体来说,Infinispan 连接到 Redis 的 Sentinel 服务器,请求 master 的名字,然后能获得正确的 master 服务器地址。这种拓扑结构通过 Redis Sentinel 提供了可用性,实现了对 Redis 服务器的失效检测和自动恢复。

<?xml version="1.0" encoding="UTF-8"?>
<infinispan
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd              urn:infinispan:config:store:redis:8.0 
http://www.infinispan.org/schemas/infinispan-cachestore-redis-config-8.0.xsd"
    xmlns="urn:infinispan:config:8.0"
    xmlns:redis="urn:infinispan:config:store:redis:8.0" >     <cache-container>
        <local-cache>
            <persistence passivation="false">
                <redis-store xmlns="urn:infinispan:config:store:redis:8.0"
                    topology="sentinel" master-name="mymaster" socket-timeout="10000" connection-timeout="10000">
                    <sentinel-server host="server1" />
                    <sentinel-server host="server2" />
                    <sentinel-server host="server3" />        <connection-pool min-idle="6" max-idle="10" max-total="20" 
min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
                </redis-store>
            </persistence>
        </local-cache>
    </cache-container>
</infinispan>#p#分页标题#e#

对于 Sentinel 模式,topology 属性需要改成 sentinel。还需要指定 master 的名字,用于选择正确的 Redis 的 master,因为一个 Sentinel 服务器可以监控多个 Redis 的 master。需要注意的是,Sentinel 服务器通过一个叫 sentinel-server 的 XML 标签来定义,这与单服务器和集群都不一样。如果没有指定,Sentinel 的默认端口是。至少需要指定一个 Sentinel 服务器,如果你有多台Sentinel 服务器,也可以都加上,这样可以 Sentinel 服务器自身也可以实现容灾。

集群

在集群拓扑结构下,Infinispan 可以连接到一个 Redis 集群。一个或多个集群节点可以加到infinispan (越多越好),被用于保存所有的数据。Redis 集群支持失效检测,所以如果集群里有master 挂掉了,就会有 slave 提升为 master。Redis 集群需要 Redis 3。

<?xml version="1.0" encoding="UTF-8"?>
<infinispan
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd              urn:infinispan:config:store:redis:8.0 
http://www.infinispan.org/schemas/infinispan-cachestore-redis-config-8.0.xsd"
    xmlns="urn:infinispan:config:8.0"
    xmlns:redis="urn:infinispan:config:store:redis:8.0" >     <cache-container>
        <local-cache>
            <persistence passivation="false">
                <redis-store xmlns="urn:infinispan:config:store:redis:8.0"
                    topology="cluster" socket-timeout="10000" connection-timeout="10000">
                    <redis-server host="server1" port="6379" />
                    <redis-server host="server2" port="6379" />
                    <redis-server host="server3" port="6379" />        <connection-pool min-idle="6" max-idle="10" max-total="20" 
min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
                </redis-store>
            </persistence>
        </local-cache>
    </cache-container>
</infinispan>#p#分页标题#e#

对于集群,topology 属性必须改成 cluster。必须指定一个或多个 Redis 集群节点,可以使用 redis-server 标签来说明。注意如果是操作集群,不支持 database ID。

一个 Redis 对应多个 Cache Store

Redis 的独立服务器模式或者 Sentinel 模式都支持 database ID。一个 database ID 可以让单个Redis 服务器支持多个独立的 database,通过一个整数 ID来区分。这可以让 Infinispan 在单个Redis 部署上支持多个 cache store,不同的 store 直接的数据可以加以隔离。Redis 集群不支持database ID。在 redis-store 标签上可以通过 database 属性定义 database ID。

<?xml version="1.0" encoding="UTF-8"?>
<infinispan
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd              urn:infinispan:config:store:redis:8.0 
http://www.infinispan.org/schemas/infinispan-cachestore-redis-config-8.0.xsd"
    xmlns="urn:infinispan:config:8.0"
    xmlns:redis="urn:infinispan:config:store:redis:8.0" >     <cache-container>
        <local-cache>
            <persistence passivation="false">
                <redis-store xmlns="urn:infinispan:config:store:redis:8.0"        topology="sentinel" master-name="mymaster" socket-timeout="10000"
 connection-timeout="10000" database="5">
                    <sentinel-server host="server1" />
                    <sentinel-server host="server2" />
                    <sentinel-server host="server3" />        <connection-pool min-idle="6" max-idle="10" max-total="20" 
min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
                </redis-store>
            </persistence>
        </local-cache>
    </cache-container>
</infinispan>#p#分页标题#e#

Redis的密码认证

Redis 可选用密码进行认证,用于增加对服务器的安全性。这需要在 cache store 连接的时候指定密码。redis-store 标签的 password 属性可以指定这个密码。

<?xml version="1.0" encoding="UTF-8"?>
<infinispan
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd              urn:infinispan:config:store:redis:8.0 
http://www.infinispan.org/schemas/infinispan-cachestore-redis-config-8.0.xsd"
    xmlns="urn:infinispan:config:8.0"
    xmlns:redis="urn:infinispan:config:store:redis:8.0" >     <cache-container>
        <local-cache>
            <persistence passivation="false">
                <redis-store xmlns="urn:infinispan:config:store:redis:8.0"        topology="sentinel" master-name="mymaster" socket-timeout="10000"
 connection-timeout="10000" password="mysecret">
                    <sentinel-server host="server1" />
                    <sentinel-server host="server2" />
                    <sentinel-server host="server3" />        <connection-pool min-idle="6" max-idle="10" max-total="20" 
min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
                </redis-store>
            </persistence>
        </local-cache>
    </cache-container>
</infinispan>

是否有SSL支持?

Redis 没有提供协议加密,而是将这个留给其他专业的软件。目前,Infinispan 集成的连接Redis服务器的 Redis 客户端(Jedis)还没有原生的对 SSL 连接的支持。#p#分页标题#e#

Infinispan 8 中新的 Redis 缓存存储实现的更多相关文章

  1. spring-boot的spring-cache中的扩展redis缓存的ttl和key名

    原文地址:spring-boot的spring-cache中的扩展redis缓存的ttl和key名 前提 spring-cache大家都用过,其中使用redis-cache大家也用过,至于如何使用怎么 ...

  2. springboot中如何向redis缓存中存入数据

    package com.hope;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jack ...

  3. 项目中遇到的Redis缓存问题

    1.Redis服务器 can not get resource from pool. 1000个线程并发还能跑,5000个线程的时候出现这种问题,查后台debug日志,发现redis 线程池不够.刚开 ...

  4. 在nodejs中怎么使用redis缓存组件

    redis量个强大的缓存组件,可以部署在windows和linux环境之上,它有五大存储结构,其中有一种为列表list,它可以实现quene和stack的功能,即队列和堆栈的功能. 当然使用先安装py ...

  5. redis缓存介绍以及常见问题浅析

    # 没缓存的日子: 对于web来说,是用户量和访问量支持项目技术的更迭和前进.随着服务用户提升.可能会出现一下的一些状况: 页面并发量和访问量并不多,mysql足以支撑自己逻辑业务的发展.那么其实可以 ...

  6. SpringBoot缓存管理(二) 整合Redis缓存实现

    SpringBoot支持的缓存组件 在SpringBoot中,数据的缓存管理存储依赖于Spring框架中cache相关的org.springframework.cache.Cache和org.spri ...

  7. Windows Azure Redis 缓存服务

    8月20日,Windows Azure (中国版)开始提供Redis缓存服务,比较国际版的Microsoft Azure晚了差不多一年的时间.说实话,微软真不应该将这个重要的功能delay这么长时间, ...

  8. java 实现redis缓存

    由于项目加载时请求数据量过大,造成页面加载很慢.采用redis作缓存,使二次访问时页面,直接取redis缓存. 1.redis连接参数 2.连接redis,设置库 3.配置文件开启缓存 4.mappe ...

  9. Spring Boot (五): Redis缓存使用姿势盘点

    1. Redis 简介 Redis 是目前业界使用最广泛的内存数据存储.相比 Memcached,Redis 支持更丰富的数据结构,例如 hashes, lists, sets 等,同时支持数据持久化 ...

随机推荐

  1. 1236 - Pairs Forming LCM -- LightOj1236 (LCM)

    http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...

  2. PHP 实现单一入口 apache配置

    在apache的httpd.conf加入,需要把LoadModule rewrite_module modules/mod_rewrite.so前面的“#”去掉 DocumentRoot / < ...

  3. psp工具需求分析

    PSP个人软件过程开发工具需求分析文档 a.业务需求    a.1 背景 二十一世纪是软件开发的黄金时期,有人把过去的十年称作软件高度发展的十年,不可置疑,越来越多的软件设计需求是物联网时代的趋势,越 ...

  4. 一些webGL的资源

    作为一个新手,把资源写在这里. 一个简介: http://www.html5china.com/HTML5features/WebGL/20111129_2985.html 类似NEHE OPENGL ...

  5. Lessons Learned 1(敏捷项目中的变更影响分析)

    问题/现象: 业务信息流转的某些环节,会向相关人员发送通知邮件,邮件中附带有链接,供相关人员进入察看或处理业务.客户要求邮件中的链接,需要进行限制,只有特定人员才能进入处理或察看.总管想了想,应道没问 ...

  6. javaweb中实现在线人数统计

    session并不是浏览器关闭时销毁的,而是在session失效的时候销毁下列代码就是监测session创建.销毁 package com.my.count; import javax.servlet ...

  7. 在centos上配置IP

    当我们安装好系统后,最先做的应该就是配置IP了,因为无论是要下载工具软件.还是远程链接,网络必不可少,所以我们要先来配置IP! 一.查看IP 如何在centos上查看IP呢,使用 ifconfig 命 ...

  8. 在 Mac OS 上创建并运行 ASP.NET Core 1.0 网站

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  9. 电子数字 网易游戏在线笔试 第一题 hihocoder

    题目链接 http://hihocoder.com/contest/ntest2016spring1/problem/1 这个题目有几个算法考点: (1)对于一个LED数码管(由7个发光二极管封装在一 ...

  10. catalina.properties

    追踪 startup.bat set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat" call "%EXECUTABLE%&q ...