110 Star 785 Fork 244

GVPqiujiayu / AutoLoadCache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
JRedis.md 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
qiujiayu 提交于 2018-12-12 23:06 . 调整说明文档代码

JRedis配置

Redis配置(基于一致性哈希算法)

<!-- Jedis 连接池配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
  <property name="maxTotal" value="2000" />
  <property name="maxIdle" value="100" />
  <property name="minIdle" value="50" />
  <property name="maxWaitMillis" value="2000" />
  <property name="testOnBorrow" value="false" />
  <property name="testOnReturn" value="false" />
  <property name="testWhileIdle" value="false" />
</bean>

<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
  <constructor-arg ref="jedisPoolConfig" />
  <constructor-arg>
    <list>
      <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis1.host}" />
      <constructor-arg type="int" value="${redis1.port}" />
      <constructor-arg value="instance:01" />
    </bean>
    <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis2.host}" />
      <constructor-arg type="int" value="${redis2.port}" />
      <constructor-arg value="instance:02" />
    </bean>
    <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis3.host}" />
      <constructor-arg type="int" value="${redis3.port}" />
      <constructor-arg value="instance:03" />
    </bean>
    </list>
  </constructor-arg>
</bean>
    
<bean id="cacheManager" class="com.jarvis.cache.redis.ShardedJedisCacheManager">
  <constructor-arg ref="hessianSerializer" />
  <property name="shardedJedisPool" ref="shardedJedisPool" />
</bean>

ShardedJedisCacheManager 中可以配置参数说明:

  • hashExpire:Hash的缓存时长:等于0时永久缓存;大于0时,主要是为了防止一些已经不用的缓存占用内存;hashExpire小于0时,则使用@Cache中设置的expire值(默认值为-1);

  • hashExpireByScript : 是否通过脚本来设置 Hash的缓存时长;

另外也可以使用 com.jarvis.cache.redis.JedisClusterCacheManager 实现对JedisCluster的操作。

Java
1
https://gitee.com/qiujiayu/AutoLoadCache.git
git@gitee.com:qiujiayu/AutoLoadCache.git
qiujiayu
AutoLoadCache
AutoLoadCache
master

搜索帮助