spring boot连接配置使用redis

 时间:2024-10-13 04:12:15

1、首先在pom.垓矗梅吒xml添加依赖,依赖内容如下<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency>

spring boot连接配置使用redis

2、如果是首次创建springboot工程可以直接在新建的时候勾选上redis

spring boot连接配置使用redis

3、上面依赖添加好了,现在设置redis连接参数数,我这里用的是yml格式的配置spring: redis: database: 0 host: ip port: 端口 password: xxx如果是另外一种配置文件直接改成这种格式即可spring.redis.database=0其他依此类型转换即可

spring boot连接配置使用redis

4、然后写个测试类,进行简单的连接测试@AutowiredStringRedisTemplate stringR髫潋啜缅edisTemplate;stringRedisTemplate.opsForValue().set("testconnect","hello world"); //设置值stringRedisTemplate.opsForValue().get("testconnect");//取值

spring boot连接配置使用redis

5、写好只后点击测试即可,下面就可以看到输出存到redis里面的值了

spring boot连接配置使用redis

6、然后可以通过idea的redis插件看里面是否多了key和值,但是似乎插件有bug

spring boot连接配置使用redis

7、如果插件用不成,直接redis服务器去查看即可,连接redis,输入密码然后keys *查看所有的key

spring boot连接配置使用redis
热门搜索
什么是龙抬头 神机妙算的意思 熬鹰是什么意思 庹读什么 六级成绩什么时候出来 腿粗穿什么裤子 什么歌曲最好听 cut是什么意思 直方图的作用 第一次约会聊什么