springboot连接redis进行CRUD:

1.添加以下依赖:

        <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>

2.在application.properties中配置redis参数

spring.redis.database=0
spring.redis.host=47.106.198.29
spring.redis.port=6379
spring.redis.password=password1
spring.redis.jedis.pool.max-wait=3600
spring.redis.jedis.pool.max-active=1
spring.redis.jedis.pool.max-idle=1
spring.redis.jedis.pool.min-idle=1
spring.redis.timeout=3600

3.编写controller类

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;@RestController
public class RedisController {@Resourceprivate RedisTemplate<String, String> redisTemplate;@RequestMapping("/set")public boolean set() {ValueOperations<String, String> stringStringValueOperations = redisTemplate.opsForValue();stringStringValueOperations.set("keyk", "valuev");return true;}@RequestMapping("/get")public String get() {ValueOperations<String, String> stringStringValueOperations = redisTemplate.opsForValue();return stringStringValueOperations.get("keyk");}@RequestMapping("/del")public boolean del() {return redisTemplate.delete("keyk");}@RequestMapping("/update ")public boolean update() {ValueOperations<String, String> stringStringValueOperations = redisTemplate.opsForValue();stringStringValueOperations.set("keyk", "valuevUpdate");return true;}
}

4.启动运行,可正常增删改查。

参考自:https://blog.csdn.net/aisu_yan/article/details/84787214

转载于:https://www.cnblogs.com/new-life/p/11152555.html

springboot连接redis进行CRUD相关推荐

  1. SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enabled

    问题描述:SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enable ...

  2. springboot连接redis错误 io.lettuce.core.RedisCommandTimeoutException:

    springboot连接redis报错 超时连接不上  可以从以下方面排查 1查看自己的配置文件信息,把超时时间不要设置0毫秒 设置5000毫秒 2redis服务长时间不连接就会休眠,也会连接不上 重 ...

  3. springboot连接redis并动态切换database(db0到db15)

    redis redis db0到db15 springboot连接redis 添加配置文件application.properties 测试是否连接成功 redis动态切换database redis ...

  4. Springboot连接redis配置

    Springboot连接redis配置 application.properties #Redis服务器地址 spring.redis.host=192.168.233.128 #Redis服务器连接 ...

  5. SpringBoot连接redis

    1 docker安装redis(6.2.2) 1.1 下载redis镜像 sudo docker pull redis:6.2.2 1.2 设置配置文件 手动创建redis.conf,并添加如下配置参 ...

  6. springboot连接redis集群

    开启redis服务和客户端 查看下当前redis的进程 [root@localhost ~]# ps -ef | grep redis 启动redis服务 [root@localhost ~]# cd ...

  7. SpringBoot连接Redis服务出现Command timed out

    问题描述:SpringBoot整合Redis,连接Redis服务时出现Command timed out 解决方法: 查看配置文件是否是设置的连接超时时间过小,一般将其设置为5000毫秒

  8. org.springframework.data.redis.RedisSystemException: Error in execution; nes遇到springboot连接Redis报错

    org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lett ...

  9. SpringBoot连接Redis集群时发生错误Cannot determine a partition to read for slot

    今天做SpringBoot和Redis整合时发生错误 io.lettuce.core.cluster.PartitionSelectorException: Cannot determine a pa ...

  10. SpringBoot连接Redis超简单

    建立一个springboot项目,什么也不用设置,建立一个最简单的就可以的,首先还是加入我们的Maven驱动包 <!-- 加入redis连接池--> <dependency>& ...

最新文章

  1. 润乾报表配置mysql数据源_润乾报表在proxool应用下的数据源配置
  2. AlexNet结构详解(引用MrGiovanni博士)
  3. 使用Hybris的customer conpon进行促销活动(promotion)
  4. android gradle proguard,Android Gradle插件2.2.0 ProGuard开始保留内部类
  5. 项目中遇到难题一 : 多条件筛选(同一本小说具有多个特征)
  6. 7-9 输出大写英文字母 (15 分)
  7. sql server序列_在SQL Server中实现序列聚类
  8. php 业务管理,PHPOA集团版协同套件:整合集团业务的管理平台
  9. Rest上传文件(利用jersey)
  10. R语言数据框行转列实例
  11. SqlServer事务回滚失败
  12. 正确的理解MySQL的MVCC及实现原理
  13. Clob,Blob,InputStream,byte 互转
  14. 电子海图领域一些概念名词的梳理
  15. 布兰迪斯大学计算机美国大学排名,美国大学排名 布兰迪斯大学排名汇总
  16. 人力资源常用理论和法则
  17. 【BZOJ4484】【JSOI2015】最小表示(拓扑排序,bitset)
  18. 一种基于自动机的快速分词方法
  19. GB9706.1-2020|小议指示灯的颜色和报警
  20. request_threaded_irq与request_irq

热门文章

  1. SpringBoot 集成 Caffeine、Redis实现双重缓存方式(二)
  2. JMX实现远程服务器Tomcat系统监控之三
  3. go和python互调
  4. 记一次去掉中间的某次merge代码
  5. 谈谈Integer中的静态类IntegerCache
  6. Spring IOC 容器源码分析 - 循环依赖的解决办法 1
  7. Apax Partners收购ThoughtWorks幕后探秘
  8. 通过定位position=fixed实现网页内容的固定层效果
  9. 【原译】一个可定制的WPF任务对话框
  10. 判断Exe文件是否正在运行的函数