关闭 x
IT技术网
    技 采 号
    ITJS.cn - 技术改变世界
    • 实用工具
    • 菜鸟教程
    IT采购网 中国存储网 科技号 CIO智库

    IT技术网

    IT采购网
    • 首页
    • 行业资讯
    • 系统运维
      • 操作系统
        • Windows
        • Linux
        • Mac OS
      • 数据库
        • MySQL
        • Oracle
        • SQL Server
      • 网站建设
    • 人工智能
    • 半导体芯片
    • 笔记本电脑
    • 智能手机
    • 智能汽车
    • 编程语言
    IT技术网 - ITJS.CN
    首页 » HTML5 »Infinispan 8 中新的 Redis 缓存存储实现

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

    2015-10-15 00:00:00 出处:daxixiong
    分享

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

    上一篇返回首页 下一篇

    声明: 此文观点不代表本站立场;转载务必保留本文链接;版权疑问请联系我们。

    别人在看

    电脑屏幕不小心竖起来了?别慌,快捷键搞定

    Destoon 模板存放规则及语法参考

    Destoon系统常量与变量

    Destoon系统目录文件结构说明

    Destoon 系统安装指南

    Destoon会员公司主页模板风格添加方法

    Destoon 二次开发入门

    Microsoft 将于 2026 年 10 月终止对 Windows 11 SE 的支持

    Windows 11 存储感知如何设置?了解Windows 11 存储感知开启的好处

    Windows 11 24H2 更新灾难:系统升级了,SSD固态盘不见了...

    IT头条

    Synology 更新 ActiveProtect Manager 1.1 以增强企业网络弹性和合规性

    00:43

    新的 Rubrik Agent Cloud 加速了可信的企业 AI 代理部署

    00:34

    宇树科技 G1人形机器人,拉动一辆重达1.4吨的汽车

    00:21

    Cloudera 调查发现,96% 的企业已将 AI 集成到核心业务流程中,这表明 AI 已从竞争优势转变为强制性实践

    02:05

    投资者反对马斯克 1 万亿美元薪酬方案,要求重组特斯拉董事会

    01:18

    技术热点

    大型网站的 HTTPS 实践(三):基于协议和配置的优化

    ubuntu下右键菜单添加新建word、excel文档等快捷方式

    Sublime Text 简明教程

    用户定义SQL Server函数的描述

    怎么在windows 7开始菜单中添加下载选项?

    SQL Server 2016将有哪些功能改进?

      友情链接:
    • IT采购网
    • 科技号
    • 中国存储网
    • 存储网
    • 半导体联盟
    • 医疗软件网
    • 软件中国
    • ITbrand
    • 采购中国
    • CIO智库
    • 考研题库
    • 法务网
    • AI工具网
    • 电子芯片网
    • 安全库
    • 隐私保护
    • 版权申明
    • 联系我们
    IT技术网 版权所有 © 2020-2025,京ICP备14047533号-20,Power by OK设计网

    在上方输入关键词后,回车键 开始搜索。Esc键 取消该搜索窗口。