springboot中redis使用和工具
application.properties
#Redis相关配置
spring.data.redis.host=localhost
#端口
spring.data.redis.port=6379
#reids 数据库索引
spring.data.redis.database = 0
RedisDao.java
package com.bank.dao;
public interface RedisDao {
// 存储验证码
boolean save(String telephone,String code);
// 获取验证码
String getCode(String telephone);
}
package com.bank.dao; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository; import java.util.concurrent.TimeUnit; @Repository
public class RedisDaoImpl implements RedisDao{ // RedisTemplate类型对象将来将从java配置类中进行注入
@Autowired
private RedisTemplate redisTemplate; //// 过期时长
// private final Long DURATION = 1 * 24 * 60 * 60 * 1000L; @Override
public boolean save(String telephone, String code) {
ValueOperations op = redisTemplate.opsForValue();
// 验证码失效时长2分钟
try{
//设置当前的key以及value值并且设置过期时间
op.set(telephone,code,120,TimeUnit.SECONDS);
return true;
} catch(Exception e){
return false;
}
} @Override
public String getCode(String telephone) {
ValueOperations op = redisTemplate.opsForValue();
//返回key中字符串的子字符
String code = (String)op.get(telephone);
return code;
}
}
依赖
<!-- Redis相关依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> <dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
(11条消息) RedisTemplate最全的常用方法_redistemplate常用方法_GavinYCF的博客-CSDN博客
springboot中redis使用和工具的更多相关文章
- SpringBoot中Redis的set、map、list、value、实体类等基本操作介绍
今天给大家介绍一下SpringBoot中Redis的set.map.list.value等基本操作的具体使用方法 上一节中给大家介绍了如何在SpringBoot中搭建Redis缓存数据库,这一节就针对 ...
- SpringBoot整合Redis并完成工具类
SpringBoot整合Redis的资料很多,但是我只需要整合完成后,可以操作Redis就可以了,所以不需要配合缓存相关的注解使用(如@Cacheable),而且我的系统框架用的日志是log4j,不是 ...
- springboot中redis取缓存类型转换异常
异常如下: [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested ...
- ③SpringBoot中Redis的使用
本文基于前面的springBoot系列文章进行学习,主要介绍redis的使用. SpringBoot对常用的数据库支持外,对NoSQL 数据库也进行了封装自动化. redis介绍 Redis是目前业界 ...
- SpringBoot中redis的使用介绍
REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C语言编写.遵守B ...
- SpringBoot中Redis的使用
转载:http://www.ityouknow.com/springboot/2016/03/06/spring-boot-redis.html Spring Boot 对常用的数据库支持外,对 No ...
- springboot中redis的缓存穿透问题
什么是缓存穿透问题?? 我们使用redis是为了减少数据库的压力,让尽量多的请求去承压能力比较大的redis,而不是数据库.但是高并发条件下,可能会在redis还没有缓存的时候,大量的请求同时进入,导 ...
- springBoot 中redis 注解缓存的使用
1,首先在启动类上加上 @EnableCaching 这个注解 在查询类的controller,或service ,dao 中方法上加 @Cacheable 更新或修改方法上加 @CachePut 注 ...
- SpringBoot整合Redis在可视化工具乱码问题,以及常用的api
pom依赖: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...
- springboot中的照片上传工具类
public class UploadImgUtils { private static String savePath = ""; /** * 上传照片工具类 * * @para ...
随机推荐
- 在Vue中实现app拍照-选取本地图库-图片上传成功后预览
基于Vue和uni-app实现手机app的功能实现和打包.拍照功能和选取本地图片使用的是HTML5的API 实现. 我为测试这个功能使用node写了个本地服务器,对于手机调试,可以通过连接同一个无线网 ...
- background-repeat属性(背景平铺)
background-repeat属性(背景平铺) 默认情况下,如果一幅背景图像不足以占满整个容器时,就会在水平方向和垂直方向重复,以填满整个容器.然而,有时候却希望背景图像只出现一次,或只在某个方向 ...
- 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组
var threeSum = function(nums) {let ans = [];const len = nums.length;if(nums == null || len < 3) r ...
- Spring 装配基础类型
1 //以String类型为例 2 <bean id="exemptSecretUser" class="java.lang.String"> 3 ...
- R7800 2.4G webshell
webshell执行 iwpriv ath1 disablecoext 1
- 学PHP的第二天!
这是我学PHP的第二天,我改了一些代码,终于把我喜欢的OJ网站的默认模板给改掉了,竟然能用!!!我从来都没有这么的欣喜过,看来PHP果真是一门非常好用的编程语言,但这个OJ有些用的是python的模块 ...
- Delphi实现大写字母键打开提示
uses XPMan 编辑框的passwordChar属性设置成 *
- 1.3 选择IDE
选择IDE 使用过的IDE 1.DEV-C++ 配合使用语言:C.C++ 个人体验:支持代码补全,信息竞赛遗留物,招很多入门教材喜欢,十分古老缺乏维护,功能简洁,安装完打开直接编译很方便,代码提示让人 ...
- Windows日常快捷键
Windows: 环境变量: Win+R,--> sysdm.cpl 计算器: Win+R,-->calc 服务:Win+R,-->services.msc 远程:Win+R,--& ...
- TFLCD编程过程中遇到的问题之.\Objects\EXTI_Project.axf: Error: L6218E: Undefined symbol POINT_COLOR (referred from tflcd.o).
在TFLCD屏幕中遇到的问题及解决方案 1.问题提出 在对正点原子提供的有关TFLCD屏幕做移植过程中,编译过程中没有报错,但是链接时就出现了报错,报错信息如下图所示: 像这种错误,无法定义到错误所在 ...