pom依赖:

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.1.RELEASE</version>
  5. <relativePath/>
  6. </parent>
  7.  
  8. <dependencies>
  9. <dependency>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-starter-data-redis</artifactId>
  12. </dependency>
  13. </dependencies>

yml配置:

  1. spring:
  2. redis:
  3. host: 127.0.0.1

配置类:

  1.  
  1. /**
    * @author GongXincheng
    * @since 2019-09-26 13:36
    */
    @Configuration
    public class RedisConfigBean {
  2.  
  3. /**
    * redis 防止key value 前缀乱码.
    *
    * @param factory redis连接 factory
    * @return redisTemplate
    */
    @Bean(name = "redisTemplate")
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
    RedisTemplate<String, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(factory);
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
    template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
    template.afterPropertiesSet();
    return template;
    }
  4.  
  5. }
  1.  

常用api:

  1. stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向redis里存入数据和设置缓存时间
  2. stringRedisTemplate.opsForValue().get("test") //根据key获取缓存中的val
  3. stringRedisTemplate.boundValueOps("test").increment(-1); //val做-1操作
  4. stringRedisTemplate.boundValueOps("test").increment(1); //val +1
  5. stringRedisTemplate.getExpire("test") //根据key获取过期时间
  6. stringRedisTemplate.getExpire("test",TimeUnit.SECONDS) //根据key获取过期时间并换算成指定单位
  7. stringRedisTemplate.delete("test"); //根据key删除缓存
  8. stringRedisTemplate.hasKey("546545"); //检查key是否存在,返回boolean值
  9. stringRedisTemplate.expire("red_123",1000 , TimeUnit.MILLISECONDS); //设置过期时间
  10. stringRedisTemplate.opsForSet().add("red_123", "1","2","3");  //向指定key中存放set集合
  11. stringRedisTemplate.opsForSet().isMember("red_123", "1")  //根据key查看集合中是否存在指定数据
  12. stringRedisTemplate.opsForSet().members("red_123");  //根据key获取set集合

SpringBoot整合Redis在可视化工具乱码问题,以及常用的api的更多相关文章

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

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

  2. springboot整合redis,并解决乱码问题。

    热烈推荐:超多IT资源,尽在798资源网 springboot 版本为 1.5.9 //如果是2.x 修改 pom.xml 也可切换成 1.5.9 <parent> <groupId ...

  3. SpringBoot整合Redis及Redis工具类撰写

            SpringBoot整合Redis的博客很多,但是很多都不是我想要的结果.因为我只需要整合完成后,可以操作Redis就可以了,并不需要配合缓存相关的注解使用(如@Cacheable). ...

  4. SpringBoot整合Redis、mybatis实战,封装RedisUtils工具类,redis缓存mybatis数据 附源码

    创建SpringBoot项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redis 引 ...

  5. Redis-基本概念、java操作redis、springboot整合redis,分布式缓存,分布式session管理等

    NoSQL的引言 Redis数据库相关指令 Redis持久化相关机制 SpringBoot操作Redis Redis分布式缓存实现 Resis中主从复制架构和哨兵机制 Redis集群搭建 Redis实 ...

  6. 九、springboot整合redis二之缓冲配置

    1.创建Cache配置类 @Configuration @EnableCaching public class RedisCacheConfig extends CachingConfigurerSu ...

  7. SpringBoot整合Redis使用Restful风格实现CRUD功能

    前言 本篇文章主要介绍的是SpringBoot整合Redis,使用Restful风格实现的CRUD功能. Redis 介绍 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-valu ...

  8. 【SpringBoot | Redis】SpringBoot整合Redis

    SpringBoot整合Redis 1. pom.xml中引入Redis相关包 请注意,这里我们排除了lettuce驱动,采用了jedis驱动 <!-- redis的依赖 --> < ...

  9. Springboot整合Redis入门完整篇,零基础入门教学教程

    记录一次简易集成Redis缓存 自定义Redisconfig配置 自定义序列化操作 加深印像 整合前提工具环境准备: 1.redis官网 https://redis.io/download 下载安装r ...

随机推荐

  1. 实现一个图片轮播-3d播放效果

    前言:最近在做一个音乐播放器,首页要做一个图片轮播,看了bootstrap的carousel插件以及移动端的swipe.js库,都是平面图片轮播的效果,所以自己想着实现类似网易云app里那种3d图片轮 ...

  2. FastEarth

    1        概述 FastEarth(后文简称FE)是自主研发的跨平台三维地理信息可视化协作平台,内置完全自主研发的XDR渲染引擎,无缝对接主流地理信息平台数据.建筑BIM.工厂PIM以及多种三 ...

  3. 从零开始的vue学习笔记(二)

    数据与方法 当一个 Vue 实例被创建时,它将 data 对象中的所有的属性加入到 Vue 的响应式系统中.data的数据和视图同步更新. 实例创建后添加一个新的属性,对这个属性的的改动将不会触发任何 ...

  4. MongoDB 学习笔记之 mongo-connector安装

    mongo-connector安装: https://github.com/mongodb-labs/mongo-connector 1. yum -y install openssl* 2.编译安装 ...

  5. 一步步剖析spring bean生命周期

    关于spring bean的生命周期,是深入学习spring的基础,也是难点,本篇文章将采用代码+图文结论的方式来阐述spring bean的生命周期,方便大家学习交流.  一  项目结构及源码 1. ...

  6. Stock Charts

    Description You're in the middle of writing your newspaper's end-of-year economics summary, and you' ...

  7. UDP方式的传输

    UDP 部分内容需要查文档学习,我们需要了解下面的两个类:java.net.DatagramSocket和java.net.DatagramPacket java.net.DatagramSocket ...

  8. drf框架序列化和返序列化

    0903自我总结 drf框架序列化和反序列化 from rest_framework import serializers 一.自己对于序列化和反序列化使用的分类 前后端交互主要有get,post,p ...

  9. PHP get_class_vars 和 (array)

    <?php class Girl { public $id = 1; public $name = 'zhy'; } $start = microtime(TRUE); var_dump(get ...

  10. 小工具---将图片文件MultipartFile保存到指定目录

    import org.springframework.web.multipart.MultipartFile; import java.io.IOException; /** 保存图片 @author ...