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. 性能测试记录: ZZ 只改5行代码获得10倍吞吐量提升

    首先得找台足够性能的机器来测试,性能不足时代码运行会出现各种奇怪的现象,导致浪费时间 文章: https://www.jianshu.com/p/4cd8596352ad   只改了5行代码吞吐量提升 ...

  2. 羊了怎么居家办公?免费不限速的远控软件RayLink一解燃眉之急!!

    近期疫情放开,各地症状不断的小阳人数量猛增(R君盼望大家早日转阴!!).不论是"羊"后居家,还是天选打工人被迫居家,远程控制公司电脑实现居家办公,成了大部分人的默契选择. 想远程控 ...

  3. CSP-J入门组

    setw(2) cout<<setw(2) //设置后面显示字符的宽度为2 cout<<fixed<<setprecision(6)<<变量名;//设置 ...

  4. WCF部署HTTP错误404.3

    错误:WCF部署HTTP错误404.3-Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加MIME映射. 解决步骤如下: 控制面板-& ...

  5. laravel 邮件发送

    1.首先你要在qq悠闲中开启你的   SMPT(设置->账户)   获取到你的授权码 2.配置laravel MAIL_DRIVER=smtpMAIL_HOST=smtp.qq.comMAIL_ ...

  6. css实现文字多余显示省略号

    只显示一行文字 overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 显示多行文字 word-break:break-all; ...

  7. MySQL索引 及 EXPLAIN

    1.索引长度计算: 1.索引字段,没有设置NOT NULL,则需要加一个字节. 2.定长字段:tinyiny占1个字节.int占4个字节.bitint占8个字节.date占3个字节.datetime占 ...

  8. threadlocal应用

    public class DataSourceSelector { /** * 线程threadlocal */ private static ThreadLocal<String> db ...

  9. Kubernetes--案例:使用Ingress发布tomcat

    假设有这样一套环境: Kubernetes集群上的tomcat-deploy控制器生成了两个运行于Pod资源中的tomcat实例,tomcat-svc是将它们统一暴露于集群中的访问入口.现在需要通过I ...

  10. python更改图片后缀名为jpg格式

    1 import os 2 import cv2 3 class GeneDataset(): 4 def __init__(self,rootdir): 5 self.rootdir = rootd ...