TestController.java 3.5 KB
Newer Older
1 2
package com.test.controller;

C
congshuo_cnki 已提交
3

4
import cn.hutool.json.JSONObject;
5 6
import com.test.conf.BloomFilterHelper;
import com.test.conf.RedisBloomFilter;
7 8 9
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.*;
C
congshuo_cnki 已提交
11
import org.springframework.web.bind.annotation.RequestMapping;
12 13
import java.util.HashMap;
import java.util.Map;
14 15

@Controller
16
@RestController
17
public class TestController {
18

19 20 21 22 23
    @Autowired
    private RedisTemplate redisTemplate;


    @RequestMapping("/get")
24
    public void get() {
25 26 27 28 29 30 31
        String key = "600LY-POP:WECHAT_API_USER_INFO:oF9P60lSv8Dh3QNWMgQ-NADwXse4";
        String value = "{\"companyLogo\":\"http://support.600ly.com/attached/image/20191218/1576640516423_original.png\",\"phoneNumber\":\"15636542518\",\"userId\":\"f03876f3087f40e4925682cc67ff8b05\",\"userName\":\"丛硕\",\"wecharId\":\"oF9P60lSv8Dh3QNWMgQ-NADwXse4\"}";
//        redisTemplate.opsForValue().set(key,value);

        Object o = redisTemplate.opsForValue().get("600LY-POP:WECHAT_API_USER_INFO:oF9P60lSv8Dh3QNWMgQ-NADwXse4");
        System.err.println(o.toString());
    }
32 33 34

    @GetMapping("test")
    public Map<String,Object> test(){
C
congshuo_cnki 已提交
35
        HashMap my = new HashMap<String, Object>();
36 37 38 39 40 41 42 43 44 45

        redisTemplate.opsForValue().set("name","cs");
        Object o = redisTemplate.opsForValue().get("name");
        my.put("name",o.toString());

        return my;
    }

    @GetMapping("testAppend")
    public Map<String,Object> test01(){
C
congshuo_cnki 已提交
46
        HashMap my = new HashMap<String, Object>();
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        redisTemplate.opsForValue().append("name","nb");
        Object o = redisTemplate.opsForValue().get("name");
        my.put("name",o.toString());

        return my;
    }


    @Autowired
    private RedisBloomFilter redisBloomFilter;

    @Autowired
    private BloomFilterHelper bloomFilterHelper;

    @ResponseBody
    @RequestMapping("/add")
63
    public String addBloomFilter(@RequestParam("redisKey") String redisKey,@RequestParam("redisValue") String redisValue,@RequestParam("booleamKey") String booleamKey) {
64 65 66


        try {
67 68 69 70
            redisBloomFilter.addByBloomFilter(bloomFilterHelper,booleamKey,redisKey);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(redisKey,redisValue);
            redisTemplate.opsForValue().set(redisKey,jsonObject.toString());
71 72 73 74 75 76 77 78
        } catch (Exception e) {
            e.printStackTrace();
            return "添加失败";
        }

        return "添加成功";
    }

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    @ResponseBody
    @RequestMapping("/getValue")
    public Map<String, Object> getValue(@RequestParam("redisKey") String redisKey,@RequestParam("booleamKey") String booleamKey){
        boolean b = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, booleamKey, redisKey);
        Map<String, Object> map = new HashMap<>();
        if (b){
            String s = redisTemplate.opsForValue().get(redisKey).toString();
            map.put(redisKey,s);
        }else {
            map.put(redisKey,"not have");
        }
        return map;
    }



95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    @ResponseBody
    @RequestMapping("/check")
    public boolean checkBloomFilter(@RequestParam ("orderNum") String orderNum) {

        boolean b = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, "bloom", orderNum);

        return b;
    }

    @GetMapping("getBloom")
    public Map<String, Object> getBloom(){
        Object o = redisTemplate.opsForValue().get("bloom");
        System.out.println(o);
        return new HashMap<>();
    }

111
}