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使用和工具的更多相关文章

  1. SpringBoot中Redis的set、map、list、value、实体类等基本操作介绍

    今天给大家介绍一下SpringBoot中Redis的set.map.list.value等基本操作的具体使用方法 上一节中给大家介绍了如何在SpringBoot中搭建Redis缓存数据库,这一节就针对 ...

  2. SpringBoot整合Redis并完成工具类

    SpringBoot整合Redis的资料很多,但是我只需要整合完成后,可以操作Redis就可以了,所以不需要配合缓存相关的注解使用(如@Cacheable),而且我的系统框架用的日志是log4j,不是 ...

  3. springboot中redis取缓存类型转换异常

    异常如下: [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested ...

  4. ③SpringBoot中Redis的使用

    本文基于前面的springBoot系列文章进行学习,主要介绍redis的使用. SpringBoot对常用的数据库支持外,对NoSQL 数据库也进行了封装自动化. redis介绍 Redis是目前业界 ...

  5. SpringBoot中redis的使用介绍

    REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C语言编写.遵守B ...

  6. SpringBoot中Redis的使用

    转载:http://www.ityouknow.com/springboot/2016/03/06/spring-boot-redis.html Spring Boot 对常用的数据库支持外,对 No ...

  7. springboot中redis的缓存穿透问题

    什么是缓存穿透问题?? 我们使用redis是为了减少数据库的压力,让尽量多的请求去承压能力比较大的redis,而不是数据库.但是高并发条件下,可能会在redis还没有缓存的时候,大量的请求同时进入,导 ...

  8. springBoot 中redis 注解缓存的使用

    1,首先在启动类上加上 @EnableCaching 这个注解 在查询类的controller,或service ,dao 中方法上加 @Cacheable 更新或修改方法上加 @CachePut 注 ...

  9. SpringBoot整合Redis在可视化工具乱码问题,以及常用的api

     pom依赖: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  10. springboot中的照片上传工具类

    public class UploadImgUtils { private static String savePath = ""; /** * 上传照片工具类 * * @para ...

随机推荐

  1. 记D365开发的最佳实践

    前端JS 不同的需求应该划分模块,以便日后修改,也是为了职责分离,模块分离,日后如果想分离到单独的JS文件里面也是比较方便: 对于公共的查询函数,应该做缓存,优先使用sessionStorage. 多 ...

  2. 03 Proxmox VE介绍

    突破困境! 企业开源虚拟化管理平台 使用Proxmox Virtual Environment 郑郁霖(Jason Cheng)著 版次:2021年12月初版 03 Proxmox VE介绍 3.1 ...

  3. constexpr和const

    const表示一个变量的值不能改变,这个值可以使运行期间得到的const int sz = get_size(); constexpr是提示编译器,该值可以在编译期间就计算出来,并进行替换,不用等到运 ...

  4. unity默认管线lightmap

    lightmap采样 https://blog.csdn.net/wodownload2/article/details/94431040

  5. centos7 安装jupyter

    1.基本包安装 yum update -y yum install python-pip -y yum install bzip2 -y yum groupinstall "Developm ...

  6. nginx文件上传模块 nginx_upload_module

    1.编译安装nginx wget https://github.com/fdintino/nginx-upload-module/archive/refs/heads/master.zip PS:原先 ...

  7. 查看Linux操作系统版本命令

    (一)查看操作系统版本的方法 1.uname -a 可以查看内核版本等信息 Linux test 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:4 ...

  8. WDA学习(24):Context Menu使用

    1.17 UI Element:Context Menu使用 本实例测试创建Context Menu. 1.创建Component,View: V_CONTEXT_MENU; 2.创建Context节 ...

  9. cadence报错because the library part is newer than the part in the design cache.Select the part in the cache and choose Design-Update Cache,and then place the part again.

    cadence报错because the library part is newer than the part in the design cache.Select the part in the ...

  10. 可视化 之D3 与echarts 对比以及应用场景

    可视化:我们想要看出一组数据的大小关系,单看数据显然不够直观.那么我们可以将它转换为一种简单易懂的图表的形式,就可以更加直观的获取数据所传递给我们的信息.这个过程就叫做数据可视化.可视化常用2个前端库 ...