Pu Zhibing
2025-04-21 efd9ac5b88dfdb3c4d2e4bcc5e7a5258aa55542c
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
package com.sinata.push.controller;
 
import com.alibaba.fastjson.JSON;
import com.sinata.push.util.RedisUtil;
import com.sinata.push.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Arrays;
import java.util.List;
 
@RestController
@RequestMapping("/redis")
public class RedisController {
 
    @Autowired
    private RedisUtil redisUtil;
 
 
    /**
     * 从redis中获取数据
     * @param key
     * @return
     */
    @ResponseBody
    @PostMapping("/getValue")
    public String getValue(String key){
        String value = redisUtil.getValue(key);
        return JSON.toJSONString(ResultUtil.success(value));
    }
 
 
 
 
    /**
     * 存值
     * @param key
     * @param value
     * @param time
     */
    @ResponseBody
    @PostMapping("/setValue")
    public String setValue(String key, String value, int time){
        redisUtil.setStrValue(key, value, time);
        return JSON.toJSONString(ResultUtil.success());
    }
 
 
    @ResponseBody
    @PostMapping("/setValue_")
    public String setValue_(String key, String value){
        redisUtil.setStrValue(key, value);
        return JSON.toJSONString(ResultUtil.success());
    }
 
    /**
     * 删除redis数据
     * @param key
     * @return
     */
    @ResponseBody
    @PostMapping("/remove")
    public String remove(String key){
        redisUtil.remove(key);
        return JSON.toJSONString(ResultUtil.success());
    }
 
 
}