SpringBoot和Redis整合非常简单

添加pom依赖

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

application.properties添加redis连接配置

spring.redis.host=192.168.2.12
spring.redis.port=6379
spring.redis.password=123456

使用RedisTemplate

针对不同的redis数据类型,spring封装了不同的template,本例只展示了StringRedisTemplate的最基本使用方法。

@RestController
@RequestMapping("redis")
public class RedisController { private final StringRedisTemplate stringRedisTemplate; @Autowired
public RedisController(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
} @GetMapping("set/{key}/{value}")
public String setString(@PathVariable String key, @PathVariable String value) {
ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
operations.append(key, value);
return "success";
}
}

redis(七)---- SpringBoot和redis整合的更多相关文章

  1. redis(Springboot中封装整合redis,java程序如何操作redis的5种基本数据类型)

    平常测试redis操作命令,可能用的是cmd窗口 操作redis,记录一下 java程序操作reids, 操作redis的方法 可以用Jedis ,在springboot 提供了两种 方法操作 Red ...

  2. 【redis】-- springboot集成redis及使用

    springboot自动配置的redis并不是特别好用,所以需要我们使用原生的jedis, 1.添加依赖 2.在application文件中配置 # Redis服务器地址 redis.host= # ...

  3. 【springboot】【redis】springboot结合redis,操作List集合实现时间轴功能

    springboot结合redis,操作List集合实现时间轴功能

  4. SpringBoot入门系列(七)Spring Boot整合Redis缓存

    前面介绍了Spring Boot 中的整合Mybatis并实现增删改查,.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/category/ ...

  5. springboot(七).springboot整合jedis实现redis缓存

    我们在使用springboot搭建微服务的时候,在很多时候还是需要redis的高速缓存来缓存一些数据,存储一些高频率访问的数据,如果直接使用redis的话又比较麻烦,在这里,我们使用jedis来实现r ...

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

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

  7. springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...

  8. springboot+shiro+redis(集群redis版)整合教程

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3.springboot+shiro+redis(单机red ...

  9. springboot+shiro+redis(单机redis版)整合教程

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(集群redis版)整合教程 3.springboot+shiro+redis(单机red ...

随机推荐

  1. pytorch max和clamp

    torch.max() torch.max(a):数组a的最大值 torch.max(a, dim=1):多维数组沿维度1方向上的最大值,若a为二维数组,则为每行的最大值(此时是对每行的每列值比较取最 ...

  2. python format使用方法

    #使用format 方法进行格式化 print("The number {1:} in hex is: {1:#x}, the number {0:} in oct is {0:o}&quo ...

  3. jenkins#配置插件加速

    系统管理 -> 插件管理  -> 高级  -> 升级站点 -> 填写新的url -> 提交. 新的url为:https://mirrors.tuna.tsinghua.e ...

  4. net Core3.1 Swagger加JWT权限

    1.Swagger中开启JWT服务 #region swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new ...

  5. Codeforces Round #554 (Div. 2) 选做

    C. Neko does Maths 题意 给 \(a,b\) ,求一个最小的 \(k\) 使得 \(\text{lcm}(a+k,b+k)\) 最小. \(a,b\le 10^9\) 题解 \(\g ...

  6. 微信浏览器 UA

    mozilla/5.0 (linux; android 5.1.1; mi note pro build/lmy47v) applewebkit/537.36 (khtml, like gecko) ...

  7. 九十四、SAP中ALV事件之八,显示功能按钮栏

    一.我们把其他代码都注释掉,直接写一行调用 SET PF-STATUS 'TIANPAN_TOOLS'. 二.运行程序,会看到我们上一篇所添加的相关功能栏图标, 三.点击不同图标,会按程序代码,有不同 ...

  8. 032-PHP中关于数组排序的usort()函数

    <?php function re($a, $b) { return ($a < $b) ? 1 : -1; } $x = array(1, 3, 2, 5, 9); usort($x, ...

  9. 1. Centos 安装

    安装 Centos 6.9 配置网络 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes ...

  10. 利用ThoughtWorks.QRCode生成二维码

    一.项目添加ThoughtWorks.QRCode.dll和System.Drawing.dll的引用 二.创建二维码公共处理类(QRCodeHandler.cs) /// <summary&g ...