forked from lxy-go/SpringBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpringboot01CacheApplicationTests.java
More file actions
55 lines (42 loc) · 1.37 KB
/
Copy pathSpringboot01CacheApplicationTests.java
File metadata and controls
55 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.wdjr.cache;
import com.wdjr.cache.bean.Employee;
import com.wdjr.cache.mapper.EmployeeMapper;
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.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Springboot01CacheApplicationTests {
@Autowired
EmployeeMapper employeeMapper;
@Autowired
StringRedisTemplate stringRedisTemplate;//操作字符串【常用】
@Autowired
RedisTemplate redisTemplate;//操作k-v都是对象
@Autowired
RedisTemplate<Object,Employee> empRedisTemplate;
@Test
public void contextLoads() {
Employee emp = employeeMapper.getEmpById(53);
System.out.println(emp);
}
/**
* redis的操作
*
*/
@Test
public void test01(){
// stringRedisTemplate.opsForValue().append("msg", "hello");
String msg = stringRedisTemplate.opsForValue().get("msg");
System.out.println(msg);
}
@Test
public void test02(){
Employee emp = employeeMapper.getEmpById(2);
empRedisTemplate.opsForValue().set("emp-01", emp);
}
}