Redis Springboot integrates Redis stand-alone

1 Introduce dependencies

	<!-- 引入redis依赖 -->
  <dependency>
  	<groupId>org.springframework.boot</groupId>
  	<artifactId>spring-boot-starter-data-redis</artifactId>
  </dependency>

2 Integrated configuration

############################################################
#
#  配置Redis
#
###########################################################
spring:
  redis:
    database: 1
    host: 192.168.51.4
    port: 6379
    password: auskat

3 Test function

package com.auskat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 类文件: RedisTestController
 * <p>
 * <p>
 * 类描述:测试控制层
 * <p>
 * 作     者: AusKa_T
 * <p>
 * 日     期: 
 * <p>
 * 时     间: 
 * <p>
 */
@RestController
@RequestMapping("/redis")
public class RedisTestController {
    
    

   @Autowired
   private RedisTemplate redisTemplate;

    @GetMapping("/set")
    public String set(String key,String value){
    
    
        redisTemplate.opsForValue().set(key,value);
        return "ok";
    }

    @GetMapping("/get")
    public String get(String key){
    
    
		   return (String)redisTemplate.opsForValue().get(key);
    }

    @GetMapping("/delete")
    public String delete(String key){
    
    
        redisTemplate.delete(key);
        return "ok";
    }


}

In general the use of StringRedisTemplateserialization operation redis

@Autowired
private StringRedisTemplate redisTemplate;

4 Related information

  • The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you

Guess you like

Origin blog.csdn.net/qq_15769939/article/details/113735333