springboot连接redis进行CRUD
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=127.0.0.1
spring.redis.port=6379
// 如果安装redis后未指定密码则不需要密码
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 { @Resource
private 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
springboot连接redis进行CRUD的更多相关文章
- springboot连接mongodb进行CRUD
springboot连接mongodb进行CRUD的过程: 在执行以下操作前已安装了mongodb并创建了用户和数据库,使用Robo 3T可成功连接. 1.创建springboot项目,加入以下mav ...
- springboot连接redis错误 io.lettuce.core.RedisCommandTimeoutException:
springboot连接redis报错 超时连接不上 可以从以下方面排查 1查看自己的配置文件信息,把超时时间不要设置0毫秒 设置5000毫秒 2redis服务长时间不连接就会休眠,也会连接不上 重 ...
- 不会用SpringBoot连接Redis,那就赶紧看这篇
摘要:如何通过springboot来集成操作Redis. 本文分享自华为云社区<SpringBoot连接Redis操作教程>,作者: 灰小猿. 今天来和大家分享一个如何通过springbo ...
- java架构之路-(Redis专题)SpringBoot连接Redis超简单
上次我们搭建了Redis的主从架构,哨兵架构以及我们的集群架构,但是我们一直还未投入到实战中去,这次我们用jedis和springboot两种方式来操作一下我们的redis 主从架构 如何配置我上次已 ...
- springboot 连接redis
引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>s ...
- SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enabled
修改redis.conf,yes 改为 no
- SpringBoot连接Redis (Sentinel模式&Cluster模式)
一.引入pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- SpringBoot整合Redis使用Restful风格实现CRUD功能
前言 本篇文章主要介绍的是SpringBoot整合Redis,使用Restful风格实现的CRUD功能. Redis 介绍 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-valu ...
- Springboot 连接 使用 Redis Example
通过一个简单的例子使用Springboot 连接并使用Redis. 本文假设已经安装好Redis. 1.首先将URL转换为一个ID ,并使用 StringRedisTemplate 将ID 和 URL ...
随机推荐
- mock打桩测试
pom依赖: <!-- https://mvnrepository.com/artifact/org.jmockit/jmockit --> <dependency> < ...
- Python-pptx库的运用
Win32com该库需要调用Microsoft PowerPoint,我将重新安装计算机Win 10,简单安装了pycharm的最新版本,然后发现创建的项目与之前的创建的项目结构不同.还有更多这样的事 ...
- c# 定义和调用索引器
- CentOS7.X基于LAMP环境搭建cacti
1.搭建好LAMP环境 2.登录数据库创建cacti create database cacti default character set utf8; 创建cacti的账户密码 grant all ...
- 在openwrt 17.01上编译最新nginx 1.14.2的笔记
openwrt 17.01源码对应的nginx版本是1.10.2,有些新功能没有,所以需要升级到nginx 1.14.2最新的稳定版 https://github.com/macports/macpo ...
- FAILED: SemanticException Unable to determine if hdfs://tmaster:8020/user/root/words.db/test_t2 is encrypted
使用hive时,建立数据库,建表,写数据: 读数据:select * from test_t2; 报错SemanticException 原因:建表时使用了其他路径,或者在另一个路径的数据库(建立数 ...
- 18计科学期总成绩明细 && 小黄衫团队预选
1.个人所有作业+团队作业总得分排名 2.千帆竞发图 3.各团队每次作业得分汇总 根据团队成绩排名,众志陈成队得分最高,预选为小黄衫团队. 对团队成绩有异议的团队,请在成绩预选发布后的两天内私信助教解 ...
- 读入 并查集 gcd/exgcd 高精度 快速幂
ios_base::sync_with_stdio(); cin.tie(); ], nxt[MAXM << ], Head[MAXN], ed = ; inline void added ...
- python装饰器,迭代器,生成器,协程
python装饰器[1] 首先先明白以下两点 #嵌套函数 def out1(): def inner1(): print(1234) inner1()#当没有加入inner时out()不会打印输出12 ...
- 【图文教程】Vmware Workstation 12虚拟机中安装CentOS 7详细步骤
文档维护人:牛棚琐思 <viprs@qq.com> ,如有不妥之处,请不吝赐教. 文档目标:帮助新手在Vmware虚拟机软件中安装CentOS 7超详细教程. 目标人群:本篇教程比较简单, ...