一:Redis简介:
Redis是一个开源(BSD许可)的内存数据结构存储,用作数据库,缓存和消息代理。
简单来说,它是一个以(key,value)的形式存储数据的数据库.
官网:https://redis.io/download 去下载对应的版本
二:使用流程:
1.解压:redis-2.4.5-win32-win64.zip
运行对应的系统版本(32bit/64bit)中的redis-server.exe和redis-cli.exe文件来启动服务和输入相应的操作.
2.图形化界面jedis下载网址:https://github.com/xetorthio/jedis。
3.Spring Data Redis 的使用介绍 官网:http://projects.spring.io/spring-data-redis/
3.1引入相关的jar包文件
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
3.2配置applicationContext.xml中的redisTemplate
<!-- 扫描redis的服务类 -->
<context:component-scan base-package="cn.itcast.redis.service" />
<!-- spring管理redis缓存管理器 -->
<bean id="redisCacheManager"
class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg index="0" ref="redisTemplate" />
</bean>
<cache:annotation-driven cache-manager="redisCacheManager"/>
<!-- jedis连接池 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="300" />
<property name="maxWaitMillis" value="3000" />
<property name="testOnBorrow" value="true" />
</bean>
<!-- jedis连接工厂 -->
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="localhost" p:port="6379" p:pool-config-ref="poolConfig"
p:database="0" />
<!-- spring-data-redis提供模板 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer">
</bean>
</property>
</bean>
3.3发送邮件保存激活码24H到redis中
//在action类中注入RedisTemplate<String,String>
@Autowired
private RedisTemplate<String,String> redisTemplate;
// 生成激活码
String activecode = RandomStringUtils.randomNumeric(32);
// 将激活码保存到redis,设置24小时失效
redisTemplate.opsForValue().set(model.getTelephone(), activecode, 24,
TimeUnit.HOURS);
3.4判断激活码是否有效
// 属性驱动
private String activecode; public void setActivecode(String activecode) {
this.activecode = activecode;
}
@Action("customer_activeMail")
public String activeMail() throws IOException {
ServletActionContext.getResponse().setContentType(
"text/html;charset=utf-8");
// 判断激活码是否有效
String activecodeRedis = redisTemplate.opsForValue().get(
model.getTelephone());
if (activecodeRedis == null || !activecodeRedis.equals(activecodeRedis)) {
// 激活码无效
ServletActionContext.getResponse().getWriter()
.println("激活码无效,请登录系统,重新绑定邮箱!");
} else {
// 激活码有效
// 防止重复绑定
// 调用CRM webService 查询客户信息,判断是否已经绑定
Customer customer = WebClient
.create("http://localhost:9002/crm_management/services"
+ "/customerService/customer/telephone/"
+ model.getTelephone())
.accept(MediaType.APPLICATION_JSON).get(Customer.class);
if (customer.getType() == null || customer.getType() != 1) {
// 没有绑定,进行绑定
WebClient.create(
"http://localhost:9002/crm_management/services"
+ "/customerService/customer/updatetype/"
+ model.getTelephone()).get();
ServletActionContext.getResponse().getWriter()
.println("邮箱绑定成功!");
} else {
// 已经绑定过
ServletActionContext.getResponse().getWriter()
.println("邮箱已经绑定过,无需重复绑定!");
} // 删除redis的激活码
redisTemplate.delete(model.getTelephone());
}
return NONE;
}
3.5编写服务器类实现对应的方法(结合WebService技术实现数据的查询与操作)
编写实体类(@XmlRootElement)-->服务类的接口
(@Path&@Get/@Post/@Push/@Delete/)-->实现类-->Dao
@Produces({ "application/xml", "application/json" })/
@Consumes({ "application/xml", "application/json" })/

Redis整合spring总结的更多相关文章

  1. Redis windows环境安装 以及 redis整合spring

    Redis对于Linux是官方支持的,安装和使用没有什么好说的,普通使用按照官方指导,5分钟以内就能搞定.详情请参考: http://redis.io/download Redis官方是不支持wind ...

  2. redis整合Spring入门

    首先 衷心感谢这篇博客给我入门时的启发  三颗心脏 你需要知道,spring的官方文档中已经注明,与redis整合时,spring的jar包版本不能低于4.2.6,否则不支持,会报错的哟 测试的时候请 ...

  3. Redis整合Spring实现分布式锁

    spring把专门的数据操作独立封装在spring-data系列中,spring-data-redis是对Redis的封装 <dependencies> <!-- 添加spring- ...

  4. Redis整合Spring结合使用缓存实例

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文介绍了如何在Spring中配置redis,并通过Spring中AOP的思想,将缓存的 ...

  5. redis整合spring @Bean写法

    jedis是一款java连接redis的客户端,spring基于jedis进行了封装,提供了简洁的操作redis的方法. 使用maven进行管理jar包之间的依赖: <dependency> ...

  6. Redis整合Spring结合使用缓存实例(转)

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文介绍了如何在Spring中配置redis,并通过Spring中AOP的思想,将缓存的 ...

  7. redis整合Spring之序列化对象与反序列化

    写在最前面 1.Spring必须是4.2.6及以上版本才支持redis 2.jar包版本建议统一 需要准备jar包 1.aopalliance-1.0.jar 2.spring-data-common ...

  8. Redis学习总结(3)——Redis整合Spring结合使用缓存实例

    摘要:本文介绍了如何在Spring中配置redis,并通过Spring中AOP的思想,将缓存的方法切入到有需要进入缓存的类或方法前面. 一.Redis介绍 什么是Redis? redis是一个key- ...

  9. Redis整合Spring结合使用缓存实例(三)

    一.Redis介绍 什么是Redis? redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

随机推荐

  1. (1)python的基础认知

    Python程序员的信仰:人生苦短,我用python! (一)python的发展史 1989年开发的语言,创始人范罗苏姆(Guido van Rossum),别称:龟叔(Guido).为了打发圣诞节假 ...

  2. 二,PHP缓存机制详解

    一,PHP缓存机制详解 我们可以使用PHP自带的缓存机制来完成页面静态化,但是仅靠PHP自身的缓存机制并不能完美的解决页面静态化,往往需要和其他静态化技术(通常是伪静态技术)结合使用. output ...

  3. jqury表单验证

    结合天天生鲜的用户注册页面,学习验证表单js register.js--表单验证源码 $(function(){ var error_name = false; var error_password ...

  4. Nginx+Apache动静分离

    Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术.动静分离技术其实是采用代理的方式,在server{}段中加入带正则匹配的location来指定匹配项 针对PHP的动 ...

  5. 极光大数据告诉你,程序员们都在"愁"些啥?

    有言道:隔行如隔山.面对不甚熟悉的人群和岗位,我们很容易在固有印象的干扰下,作出一些偏离实际的解读.比如在很多外行人眼中,程序员群体的固有形象是性格木讷,生活方式通常也比较宅.他们最大的爱好就是玩游戏 ...

  6. TortoiseSVN查看修改时报错的解决方法

    提交Bug后很快就修复了,给Stefan点个赞.大家等新版本(1.11.1)发布就可以了. -------------------------分割线下是原文---------------------- ...

  7. 大数据平台-java、mysql安装

    补充: 对于ssh登录不是特定端口22的,进行文件修改 vim /etc/ssh/sshd_config Port 61333 简化后序命令输入,修改文件如下:  一.java环境安装 一共5台服务器 ...

  8. python使用easyinstall安装xlrd、xlwt、pandas等功能模块的方法

    在日常工作中,使用Python时经常要引入一些集成好的第三方功能模块,如读写excel的xlrd和xlwt模块,以及数据分析常用的pandas模块等. 原生的python并不含这些模块,在使用这些功能 ...

  9. dubbo序列化hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决

    dubbo序列化,hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决 转载声明: ...

  10. JBoss7.1.1远程无法访问

    一般情况下在JBoss7.1.1.Final版本中配置standalone/configuration/standalone.xml<interfaces>里面name为public的&l ...