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

    上一篇返回首页 下一篇

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

    别人在看

    正版 Windows 11产品密钥怎么查找/查看?

    还有3个月,微软将停止 Windows 10 的更新

    Windows 10 终止支持后,企业为何要立即升级?

    Windows 10 将于 2025年10 月终止技术支持,建议迁移到 Windows 11

    Windows 12 发布推迟,微软正全力筹备Windows 11 25H2更新

    Linux 退出 mail的命令是什么

    Linux 提醒 No space left on device,但我的空间看起来还有不少空余呢

    hiberfil.sys文件可以删除吗?了解该文件并手把手教你删除C盘的hiberfil.sys文件

    Window 10和 Windows 11哪个好?答案是:看你自己的需求

    盗版软件成公司里的“隐形炸弹”?老板们的“法务噩梦” 有救了!

    IT头条

    公安部:我国在售汽车搭载的“智驾”系统都不具备“自动驾驶”功能

    02:03

    液冷服务器概念股走强,博汇、润泽等液冷概念股票大涨

    01:17

    亚太地区的 AI 驱动型医疗保健:2025 年及以后的下一步是什么?

    16:30

    智能手机市场风云:iPhone领跑销量榜,华为缺席引争议

    15:43

    大数据算法和“老师傅”经验叠加 智慧化收储粮食尽显“科技范”

    15:17

    技术热点

    商业智能成CIO优先关注点 技术落地方显成效(1)

    用linux安装MySQL时产生问题破解

    JAVA中关于Map的九大问题

    windows 7旗舰版无法使用远程登录如何开启telnet服务

    Android View 事件分发机制详解

    MySQL用户变量的用法

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

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