Infinispan 8 中新的 Redis 缓存存储实现
转载于: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 缓存存储实现的更多相关文章
- spring-boot的spring-cache中的扩展redis缓存的ttl和key名
原文地址:spring-boot的spring-cache中的扩展redis缓存的ttl和key名 前提 spring-cache大家都用过,其中使用redis-cache大家也用过,至于如何使用怎么 ...
- springboot中如何向redis缓存中存入数据
package com.hope;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jack ...
- 项目中遇到的Redis缓存问题
1.Redis服务器 can not get resource from pool. 1000个线程并发还能跑,5000个线程的时候出现这种问题,查后台debug日志,发现redis 线程池不够.刚开 ...
- 在nodejs中怎么使用redis缓存组件
redis量个强大的缓存组件,可以部署在windows和linux环境之上,它有五大存储结构,其中有一种为列表list,它可以实现quene和stack的功能,即队列和堆栈的功能. 当然使用先安装py ...
- redis缓存介绍以及常见问题浅析
# 没缓存的日子: 对于web来说,是用户量和访问量支持项目技术的更迭和前进.随着服务用户提升.可能会出现一下的一些状况: 页面并发量和访问量并不多,mysql足以支撑自己逻辑业务的发展.那么其实可以 ...
- SpringBoot缓存管理(二) 整合Redis缓存实现
SpringBoot支持的缓存组件 在SpringBoot中,数据的缓存管理存储依赖于Spring框架中cache相关的org.springframework.cache.Cache和org.spri ...
- Windows Azure Redis 缓存服务
8月20日,Windows Azure (中国版)开始提供Redis缓存服务,比较国际版的Microsoft Azure晚了差不多一年的时间.说实话,微软真不应该将这个重要的功能delay这么长时间, ...
- java 实现redis缓存
由于项目加载时请求数据量过大,造成页面加载很慢.采用redis作缓存,使二次访问时页面,直接取redis缓存. 1.redis连接参数 2.连接redis,设置库 3.配置文件开启缓存 4.mappe ...
- Spring Boot (五): Redis缓存使用姿势盘点
1. Redis 简介 Redis 是目前业界使用最广泛的内存数据存储.相比 Memcached,Redis 支持更丰富的数据结构,例如 hashes, lists, sets 等,同时支持数据持久化 ...
随机推荐
- IE9下WebUploader上传图片跨域问题
作为前端,这一次踩到后台xml配置的坑. IE9下上传图片通过flash插件,一直发送http://192.168.0.8:8888/crossdomain.xml请求,状态码为404,原因是上传图片 ...
- js高阶函数
我是一个对js还不是很精通的选手: 关于高阶函数详细的解释 一个高阶函数需要满足的条件(任选其一即可) 1:函数可以作为参数被传递 2:函数可以作为返回值输出 吧函数作为参数传递,这代表我们可以抽离一 ...
- LinkedHahsMap和HashMap的比较
http://www.cnblogs.com/hubingxu/archive/2012/02/21/2361281.html#commentform 一般情况下,我们用的最多的是HashMap,在M ...
- 51nod 1138 连续整数的和(数学公式)
1138 连续整数的和 #include <iostream> #include <cmath> #include <cstdio> using namespace ...
- AKI
KDIGO 2012定义:尿量<0.5ml/kg/h 6h+:scr上升50%+ 7d-:scr上升26.5 2d- 但面对录入窗口,又想不出说什么了,继续看aki?刚才想的是什么呢?入冬,好像 ...
- 【NHibernate】列“ReservedWord”不属于表 ReservedWords
NHibernate+FluentNHibernate+MySql 运行时黄页显示下边的异常,项目中找了半天没出现过这个列的关键字. [ArgumentException: 列“ReservedWor ...
- Jquery Mobile 学习笔记(一)
1.模拟器,IOS:XCODE GENYMOTION ANDROID:ECLIPSE GENYMOTION 2.jquery mobile data-role=page 代表一个页面 data-po ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- select 取的是session里面的值时
原来是写了一个select标签,然后用js循环取出来,发现问题是本来嵌在页面右边的页面整个弹出来, 后来改成html:optionsCollection就好了: 效果图:
- Python成长笔记 - 基础篇 (十三)--堡垒机
堡垒机架构 堡垒机的主要作用权限控制和用户行为审计,堡垒机就像一个城堡的大门,城堡里的所有建筑就是你不同的业务系统 , 每个想进入城堡的人都必须经过城堡大门并经过大门守卫的授权,每个进入城堡的人必须且 ...