Spring Boot:Redis

一、创建Springboot+Redis项目
Spring Boot:Redis_第1张图片
1.jpg
  1. pom.xml


    4.0.0

    com.github.davidji80.springboot
    redis
    0.0.1-SNAPSHOT
    jar

    redis
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.5.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

  1. application.yml
spring:
  redis:
    database: 1
    host: 192.168.1.7
    port: 6379
  1. controller
    controller中直接注入StringRedisTemplate
package com.github.davidji80.springboot.redis.controller;

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

@RestController
public class RedisController {
    @Autowired
    StringRedisTemplate redis;

    @RequestMapping("/set/{name}")
    public String sendMsgToMq(@PathVariable String name) {
        redis.opsForValue().set("abc",name);
        return "123";
    }
}

代码

https://github.com/DavidJi80/springboot
v0.6

你可能感兴趣的:(Spring Boot:Redis)