一: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. 百度联盟广告 http://cpro.baidustatic.com/cpro/ui/c.js

    <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript" ...

  2. kvm linux虚拟机在线扩展磁盘

    说明: 1) vmware ESXi虚拟化平台也支持这台在线扩展磁盘功能. 2) kvm虚拟机也支持在线扩展磁盘功能,在线扩展有特定的使用环境,主要用于不能随便停用的生产环境中. 3) 经过测试KVM ...

  3. 案例1-合并2个不同文件夹中的csv文件到另外一个目录,相同的文件名进行数据合并,不同的文件名直接移到新文件夹

    发现在ubuntu和centos中有些命令还不一样,比如<<<可在centos中使用,但是ubuntu中不行 csv文件名以及格式如下 3669_20180121.csv 总笔数,2 ...

  4. Event(补交作业)

    三种方法可以创建Eventhandler 1.

  5. 编程开发之--Oracle数据库--存储过程和存储函数(1)

    1.存储过程和存储函数 描述:指存储在数据库中供所有用户程序调用的子程序叫做存储过程.存储函数 区别:存储函数可以通过return子句返回一个函数的值 (1)存储过程 语法:create [or re ...

  6. [原创]PHP 异常错误处理

    目录 错误与异常 异常类 错误类(PHP >= 7) 错误 错误报告级别 错误报告设置 全局异常处理程序 全局错误处理函数 无法捕获的错误类型 范例代码 开发/生产环境处理错误和异常 开发环境 ...

  7. createFile

    #include<iostream> #include<windows.h> #include<stdio.h> using namespace std; int ...

  8. 主流服务器虚拟化技术简单使用——Xen(二)

    管理多台Xen主机可以使用GUI工具virt-manager和xm.xl等命令行工具. Tips:hypervisor一定要选到Xen web管理工具 Xen也有一个简易web管理工具叫xenwebm ...

  9. java8特性之Lambda表达式

    1.典型的用Lambda表达式的场景 如果有这样的一个小应用,其中的一个类Student包含姓名(name),性别(sex),分数(score),如下: package demo; public cl ...

  10. 在Keras中使用tensorboard可视化acc等曲线

    1.使用tensorboard可视化ACC,loss等曲线 keras.callbacks.TensorBoard(log_dir='./Graph', histogram_freq= 0 , wri ...