package com.test.controller; import cn.hutool.json.JSONObject; import com.test.conf.BloomFilterHelper; import com.test.conf.RedisBloomFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping; import java.util.HashMap; import java.util.Map; @Controller @RestController public class TestController { @Autowired private RedisTemplate redisTemplate; @RequestMapping("/get") public void get() { 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()); } @GetMapping("test") public Map test(){ HashMap my = new HashMap(); redisTemplate.opsForValue().set("name","cs"); Object o = redisTemplate.opsForValue().get("name"); my.put("name",o.toString()); return my; } @GetMapping("testAppend") public Map test01(){ HashMap my = new HashMap(); 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") public String addBloomFilter(@RequestParam("redisKey") String redisKey,@RequestParam("redisValue") String redisValue,@RequestParam("booleamKey") String booleamKey) { try { redisBloomFilter.addByBloomFilter(bloomFilterHelper,booleamKey,redisKey); JSONObject jsonObject = new JSONObject(); jsonObject.put(redisKey,redisValue); redisTemplate.opsForValue().set(redisKey,jsonObject.toString()); } catch (Exception e) { e.printStackTrace(); return "添加失败"; } return "添加成功"; } @ResponseBody @RequestMapping("/getValue") public Map getValue(@RequestParam("redisKey") String redisKey,@RequestParam("booleamKey") String booleamKey){ boolean b = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, booleamKey, redisKey); Map map = new HashMap<>(); if (b){ String s = redisTemplate.opsForValue().get(redisKey).toString(); map.put(redisKey,s); }else { map.put(redisKey,"not have"); } return map; } @ResponseBody @RequestMapping("/check") public boolean checkBloomFilter(@RequestParam ("orderNum") String orderNum) { boolean b = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, "bloom", orderNum); return b; } @GetMapping("getBloom") public Map getBloom(){ Object o = redisTemplate.opsForValue().get("bloom"); System.out.println(o); return new HashMap<>(); } }