SpringBoot_Redis配置

Spring Boot  redis

1、添加依赖

<!-- 引入 spring-boot-starter-redis 当前最新版本-->
<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-redis</artifactId>

<version>1.4.1.RELEASE</version>

</dependency>

2、编写配置application.yml

spring:    

redis: 

    host: 127.0.0.1 

3、启动redis服务器,编写测试类

package com.springboot.test.test;


import java.util.List;


import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.springboot.test.Application;

import com.springboot.test.mapper.UserMapper;

import com.springboot.test.pojo.User;


@RunWith(SpringJUnit4ClassRunner.class)

@SpringBootTest(classes= {Application.class})

public class SpringBootJunitTest {


@Autowired

private UserMapper userMapper;


@Test

public void findall() {

List<User> list = userMapper.findAll();

System.out.println(list);

}


@Autowired

private RedisTemplate redisTemplate;

@Test

public void testRedis() {

redisTemplate.boundValueOps("springboot").set("123456");;

}

@Test

public void testRedis1() {

String str = (String) redisTemplate.boundValueOps("springboot").get();

System.out.println(str);

}

}

 

posted @ 2017-02-20 11:19  zhangqi0828  阅读(193)  评论(0编辑  收藏  举报