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 ...
随机推荐
- (四)REDIS-布隆过滤器及缓存
(一)布隆过滤器 布隆过滤器(英语,Bloom Filter)是1970年由布隆提出的.它实际是一个很长的二进制数组+多个随机Hash算法映射函数,主要用于判断一个元素是否在集合中. 通常我们会遇到很 ...
- Unity中的深度测试相关知识与问题
https://www.jianshu.com/p/f420b55edd0b?utm_campaign=hugo
- pgsql 查询结果转换为json数组
select array_to_json(array_agg(row_to_json(t))) from (SELECT * FROM test) t
- imputation文献-A systematic evaluation of single-cell RNA-sequencing imputation methods
文章题目 A systematic evaluation of single-cell RNA-sequencing imputation methods 中文名: 单细胞RNA测序插补方法的系统评价 ...
- vue 移动端px转rem
1.安装lib-flexible 终端执行命令:npm i lib-flexible --save 2.在main.js引入lib-flexible 3.终端执行命令:npm install post ...
- [BOM]前端解析cookie为对象
参考解析页面传参 var cookie_str = document.cookie var cookie_arr = cookie_str.split("; ") var cook ...
- vue-cli打包后运行报路径错误 不知道什么牛马问题 连默认生成的项目不动一行代码直接打包都会出错
不知道什么牛马问题 连默认生成的项目不动一行代码直接打包都会出错 解决方法 新建一个 vue.config.js module.exports = { publicPath: './', config ...
- python基于百度unit实现语音识别与语音交互
一.百度Unit新建机器人 网址:https://ai.baidu.com/tech/speech/asr: 1.新建机器人并添加预置技能步骤 (1).新建机器人(添加预置技能),并填写机器人具体信息 ...
- bcc分析缓存命中率
系统环境:centos7/redhat7 安装,提前配好网络yum源,比如aliyun yum install bcc-tools /etc/profile 添加如下命令路径 vim /etc/pro ...
- Ant Design 分页数据回显问题
我们可以创建一个新的值来保存这些数据allSingleSelectedRowKeys: 下面是我们的HTML结构 <a-table :row-selection="{ selected ...