基本使用

首先添加依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

默认会连接到localhost:6379 所以项目中不需要进行任何的配置就可以使用自动配置已经配置好的 3个类型 RedisConnectionFactory, StringRedisTemplate, RedisTemplate

配置:

  @Beanpublic RedisTemplate redisTemplate2(RedisConnectionFactory redisConnectionFactory){RedisTemplate<Object, Object> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory);//这里配置一个序列化器StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();template.setKeySerializer(stringRedisSerializer);template.setHashKeySerializer(stringRedisSerializer);GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();template.setValueSerializer(genericJackson2JsonRedisSerializer);template.setHashValueSerializer(genericJackson2JsonRedisSerializer);return template;}

server类:

 @Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate StringRedisTemplate stringRedisTemplate;public void doSth(){redisTemplate.opsForValue().set("boot","test");stringRedisTemplate.opsForValue().set("bootStr","test2");}

启动类:

@SpringBootApplication
public class Ch08Application implements CommandLineRunner {public static void main(String[] args) {SpringApplication.run(Ch08Application.class, args);}@Autowiredprivate RedisDemo redisDemo;@Overridepublic void run(String... args) throws Exception {redisDemo.doSth();}
}

SpringBoot---------Redis相关推荐

  1. Java项目:在线淘房系统(租房、购房)(java+SpringBoot+Redis+MySQL+Vue+SpringSecurity+JWT+ElasticSearch+WebSocket)

    源码获取:博客首页 "资源" 里下载! 该系统有三个角色,分别是:普通用户.房屋中介.管理员.普通用户的功能:浏览房屋信息.预约看房.和中介聊天.申请成为中介等等.房屋中介的功能: ...

  2. Springboot + redis + 注解 + 拦截器来实现接口幂等性校验

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 作者:wangzaiplus www.jianshu.com/p/ ...

  3. springboot + redis + 注解 + 拦截器 实现接口幂等性校验

    点击上方"方志朋",选择"设为星标" 做积极的人,而不是积极废人 来源:https://www.jianshu.com/p/6189275403ed 一.概念 ...

  4. 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能...

    springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...

  5. redis 判断存在性_实战 | springboot+redis+拦截器 实现接口幂等性校验

    来源:https://www.jianshu.com/p/6189275403ed 一.概念 幂等性, 通俗的说就是一个接口, 多次发起同一个请求, 必须保证操作只能执行一次 比如: 订单接口, 不能 ...

  6. springboot redis token_Spring Boot + Redis + 注解 + 拦截器来实现接口幂等性校验

    优质文章,及时送达 作者 | wangzaiplus 链接 | www.jianshu.com/p/6189275403ed 一.概念 幂等性, 通俗的说就是一个接口, 多次发起同一个请求, 必须保证 ...

  7. C#session共享+redis_技术干货分享:基于SpringBoot+Redis的Session共享与单点登录

    categories: 架构 author: mrzhou tags: SpringBoot redis session 单点登录 基于SpringBoot+Redis的Session共享与单点登录 ...

  8. 补习系列(14)-springboot redis 整合-数据读写

    目录 一.简介 二.SpringBoot Redis 读写 A. 引入 spring-data-redis B. 序列化 C. 读写样例 三.方法级缓存 四.连接池 小结 一.简介 在 补习系列(A3 ...

  9. SpringBoot Redis缓存 @Cacheable、@CacheEvict、@CachePut

    SpringBoot Redis缓存 @Cacheable.@CacheEvict.@CachePut

  10. SpringBoot+Redis+Cookies实现高并发的购物车

    案例实战:SpringBoot+Redis+Cookies实现高并发的购物车 步骤1:代码逻辑 /*** 添加购物车*/@PostMapping(value = "/addCart" ...

最新文章

  1. 计算机模拟组装测试题一,江苏专转本计算机模拟自测试题(一)
  2. springboot 读取配置文件内容的几种方式
  3. jQuery实现id模糊查询
  4. wpf custom control
  5. windows下ngnix+php配置
  6. Scala Case类和对象
  7. 学python怎么教_学神IT教你Python应该怎么学
  8. 安卓学习 之 Service服务(十)
  9. java xy,java – 某个z深度的xy位置
  10. Linux笔记-iptables开放指定端口,开放ICMP协议,其他端口禁止访问
  11. zabbix监控windows服务器简单介绍
  12. Keras——保存和提取模型
  13. python iloc iat_python数据预处理_DataFrame数据筛选loc,iloc,ix,at,iat
  14. MDK5 安装指导书
  15. 【7gyy】电脑磁盘分区需要注意的问题
  16. [魔方]魔教秘籍4:《封王-易筋经》(概要)
  17. 在线数据图表制作-FineReport文本控件
  18. 帮我写一篇向女孩子表白的情书
  19. 网站 被降权的四种处理方法
  20. 在美国高校找教职及教学中的体会

热门文章

  1. 【高速接口-RapidIO】2、RapidIO串行物理层的包与控制符号
  2. 什么是域名服务器 (DNS) 及其工作原理?
  3. Spring(注解)详解
  4. mysql进程daemon_守护进程详解及创建,daemon()使用
  5. 《易经》与二进制的发明
  6. MingW下载与安装
  7. 鱼c论坛 python课后题pdf_[全套55讲]鱼C论坛小甲鱼Python的课后题.pdf
  8. JAVA JDK jdk 安装 下载后双击没反应
  9. 硬盘检测软件测试培训,认识专业的考机工具PassMark BurnInTest_软件测试_软件测试培训_软件测试频道_中国IT实验室...
  10. 企业升级改造项目中的电力监控系统的研究与应用