项目Redis集成

 项目使用Redis

一、导入JAR包

<dependency>
       <groupId>com.uns.inf</groupId>
       <artifactId>unsc</artifactId>
       <version>0.0.1</version>
</dependency>

 

二、配置spring-unsc.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:unscache="http://www.uns.com/schema/uns-cache"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.uns.com/schema/uns-cache http://www.uns.com/schema/uns-cache/uns-cache-1.0.0.xsd">
	<unscache:config appName="rule_engine">
		<unscache:redis connection-cache-size="2"
			connection-max-size="20" timeout="5000"
			servers="172.22.203.171:7001,172.22.203.171:7002" />
	</unscache:config>
</beans>

 

 三、属性讲解

Config参数说明:

appName 应用名称必输

serialization 序列化方式(默认json)可选

ttl 缓存时间(默认1800秒)可选

origin 缓存位置(默认远程、分本地和远程)可选

switch 缓存开关(默认true,false时缓存不起作用)可选

redis参数说明:

整项可选(不配置时缓存本地)

connection-cache-size redis空闲连接数

connection-max-size redis最大连接数

timeout redis超时时间

servers redis集群地址(格式是服务地址+端口,多个地址用逗号隔开)

 

四、注解使用

方法上指定@UnsCache

全部参数如下,只有特殊情况下再配置相应的参数

@UnsCache(key="",action=Action.CLEAN,origin=OriginType.LOCAL,prefix="",scope=Scope.Local,seriatype=SeriaType.DEFAULT,ttl=1213)

参数说明:

Key 指定缓存key(默认系统自己计算)可选

Prefix 指定key的前缀可选

Action 操作类型(默认是NONE,clean是清除缓存,refresh是刷新缓存)可选

Origin 选择缓存的位置(默认远程、分本地和远程)可选

Scope 缓存的范围(是本应用使用还是所有应用使用)可选

Seriatype序列化方式(默认json)可选

Ttl 指定缓存时间(默认1800秒)可选

五、静态使用(静态类)

本地

UnsLocalCache

redis远程

UnsRedisCache

UnsRedisCache.removeValue(key);

UnsRedisCache.hincrByFloat(key, "RULE_ENGINCE", value.doubleValue());

 

 

六、JAR包下载(见附件)

 

七、使用实例

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值