當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot连接Redis超简单
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot连接Redis超简单
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
建立一個springboot項目,什么也不用設置,建立一個最簡單的就可以的,首先還是加入我們的Maven驅動包
<!-- 加入redis連接池--> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId> </dependency>加入我們的redis的配置信息,放置在application.yml文件下即可。
spring:redis:host: 192.168.31.101port: 6379password: 123456jedis:pool:max-active: 8max-wait: -1max-idle: 500min-idle: 0lettuce:shutdown-timeout: 0我們直接來上測試類吧
package com.abbey.myblog.controller;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.data.redis.core.StringRedisTemplate;/*** @author lianying* @create 2020-11-22 3:43 下午**/ @RestController @RequestMapping("/redis") public class RedisController {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@GetMapping(value = "getUserByRedis")public String getIndex(){stringRedisTemplate.opsForValue().set("xiaocai", "888");String res = stringRedisTemplate.opsForValue().get("xiaocai");System.out.println(res);return res;} }瀏覽器輸入地址驗證
直接自動裝配一下StringRedisTemplate即可,剩下的就是redis操作了,五種數據的基本操作如下。
redisTemplate.opsForValue();//操作字符串 redisTemplate.opsForHash();//操作hash redisTemplate.opsForList();//操作list redisTemplate.opsForSet();//操作set redisTemplate.opsForZSet();//操作有序set?
?
總結
以上是生活随笔為你收集整理的SpringBoot连接Redis超简单的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Git新建分支出现fatal: Not
- 下一篇: SpringBoot+Redis(实现处