RedisController.java
3 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.huaheng.common.redis.controller;
import com.huaheng.common.redis.model.RedisModel;
import com.huaheng.common.redis.serviceimpl.RedisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class RedisController {
@Autowired
private RedisServiceImpl service;
//添加
// @RequestMapping(value = "/add", method = RequestMethod.GET)
public void test() {
System.out.println("start.....");
RedisModel m = new RedisModel();
m.setName("张三");
m.setTel("1111");
m.setAddress("长沙");
m.setRedisKey("zhangsanKey01");
service.put(m.getRedisKey(), m, -1);
RedisModel m2 = new RedisModel();
m2.setName("张三2");
m2.setTel("2222");
m2.setAddress("长沙2");
m2.setRedisKey("zhangsanKey02");
service.put(m2.getRedisKey(), m2, -1);
RedisModel m3 = new RedisModel();
m3.setName("张三3");
m3.setTel("2222");
m3.setAddress("长沙3");
m3.setRedisKey("zhangsanKey03");
service.put(m3.getRedisKey(), m3, -1);
System.out.println("add success end...");
}
//查询所有对象
// @RequestMapping(value = "/getAll", method = RequestMethod.GET)
// @ResponseBody
public Object getAll() {
return service.getAll();
}
//查询所有key
// @RequestMapping(value = "/getKeys", method = RequestMethod.GET)
// @ResponseBody
public Object getKeys() {
return service.getKeys();
}
//根据key查询
// @RequestMapping(value = "/get", method = RequestMethod.GET)
public Object get(String key) {
RedisModel m = new RedisModel();
m.setRedisKey(key);
return service.get(m.getRedisKey());
}
//删除
// @RequestMapping(value = "/remove", method = RequestMethod.GET)
// @ResponseBody
public void remove() {
RedisModel m = new RedisModel();
m.setRedisKey("zhangsanKey01");
service.remove(m.getRedisKey());
}
//判断key是否存在
// @RequestMapping(value = "/isKeyExists", method = RequestMethod.GET)
// @ResponseBody
public void isKeyExists() {
RedisModel m = new RedisModel();
m.setRedisKey("zhangsanKey01");
boolean flag = service.isKeyExists(m.getRedisKey());
System.out.println("zhangsanKey01 是否存在: "+flag);
}
//查询当前缓存的数量
// @RequestMapping(value = "/count", method = RequestMethod.GET)
// @ResponseBody
public Object count() {
return service.count();
}
//清空所有key
// @RequestMapping(value = "/empty", method = RequestMethod.GET)
// @ResponseBody
public void empty() {
service.empty();
}
}