Login
网站首页 > 文章中心 > 其它

【SpringBoot】整合Redis实战_springboot连接Redis

作者:小编 更新时间:2023-08-12 18:58:12 浏览量:163人看过

【SpringBoot】整合Redis实战_springboot连接Redis-图1

【SpringBoot】整合Redis实战_springboot连接Redis

通过缓存减少数据库访问,提高访问速度

①.、redis官网 https://redis.io/download

简介:使用springboot-starter整合reids实战

# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时spring.redis.pool.max-wait=1000

①.、注入模板@Autowiredprivate StirngRedisTemplate strTplRedis

package com.atguigu.springboot.controller;




import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.springboot.controller.domain.JsonData;


@RestController
@RequestMapping("/api/v1/redis")
public class RdisTestController {

private StringRedisTemplate redisTpl; //jdbcTemplate

@GetMapping(value="add")
public Object add(){
    //opsForValue : Returns the operations performed on simple values (or Strings in Redis terminology).
 
    redisTpl.opsForValue().set("name", "xdclass2018");
    return JsonData.buildSuccess();
@GetMapping(value="get")
public Object get(){
    String value = redisTpl.opsForValue().get("name");        
    return JsonData.buildSuccess(value);

}

controller

以上就是土嘎嘎小编为大家整理的【SpringBoot】整合Redis实战相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章