2KB项目,专业的源码交易网站 帮助 收藏 每日签到

Infinispan 8 中新的 Redis 缓存存储实现

  • 时间:2019-01-23 18:30 编辑:2KB 来源:2KB.COM 阅读:366
  • 扫一扫,手机访问
  • 分享
摘要:
Infinispan Redis 英文原文:New Redis Cache Store Introduced in Infinispan 8

Infinispan 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>

注意 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>

对于 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>

对于集群,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>

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 连接的支持。

本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接。 2KB翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。


2KB项目(www.2kb.com,源码交易平台),提供担保交易、源码交易、虚拟商品、在家创业、在线创业、任务交易、网站设计、软件设计、网络兼职、站长交易、域名交易、链接买卖、网站交易、广告买卖、站长培训、建站美工等服务

  • 全部评论(0)
资讯详情页最新发布上方横幅
最新发布的资讯信息
【计算机/互联网|】Nginx出现502错误(2020-01-20 21:02)
【计算机/互联网|】网站运营全智能软手V0.1版发布(2020-01-20 12:16)
【计算机/互联网|】淘宝这是怎么了?(2020-01-19 19:15)
【行业动态|】谷歌关闭小米智能摄像头,因为窃听器显示了陌生人家中的照片(2020-01-15 09:42)
【行业动态|】据报道谷歌新闻终止了数字杂志,退还主动订阅(2020-01-15 09:39)
【行业动态|】康佳将OLED电视带到美国与LG和索尼竞争(2020-01-15 09:38)
【行业动态|】2020年最佳AV接收机(2020-01-15 09:35)
【行业动态|】2020年最佳流媒体设备:Roku,Apple TV,Firebar,Chromecast等(2020-01-15 09:31)
【行业动态|】CES 2020预览:更多的流媒体服务和订阅即将到来(2020-01-08 21:41)
【行业动态|】从埃隆·马斯克到杰夫·贝佐斯,这30位人物定义了2010年代(2020-01-01 15:14)
联系我们

Q Q: 7090832

电话:400-0011-990

邮箱:7090832@qq.com

时间:9:00-23:00

联系客服
商家入住 服务咨询 投拆建议 联系客服
0577-67068160
手机版

扫一扫进手机版
返回顶部