SpringBoot quick integration of Redis tutorial

  1. Add springboot redis dependency
 <!--配置Redis依赖-->
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-redis</artifactId>
 </dependency>
  1. Add Redis configuration to spring boot yaml file
spring:
  redis:
    database: 0
    host: 192.168.233.130
    port: 6379
    password: 123456
  1. New test Controller
@ApiIgnore
@RestController
@RequestMapping("redis")
public class RedisController {
    
    

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

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

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

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

RedisTemplate injection problem reference: https://blog.csdn.net/LIZHONGPING00/article/details/115314418
4. Use RDM to view remote operation Redis data.
Insert picture description here
The key and value of the operation seem to be garbled, which is related to its own serialization mechanism.

Guess you like

Origin blog.csdn.net/LIZHONGPING00/article/details/115315066