|
@@ -0,0 +1,57 @@
|
|
|
+package com.qmth.demo.api.controller;
|
|
|
+
|
|
|
+import com.qmth.boot.api.annotation.Aac;
|
|
|
+import com.qmth.boot.api.annotation.BOOL;
|
|
|
+import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/redis")
|
|
|
+@Aac(strict = BOOL.FALSE, auth = BOOL.FALSE)
|
|
|
+public class RedisController {
|
|
|
+
|
|
|
+ //@Resource
|
|
|
+ //private RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
+ @RequestMapping("/get")
|
|
|
+ public Object get(@RequestParam String key) {
|
|
|
+ return redissonClient.getBucket(key).get();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/put")
|
|
|
+ public Object put(@RequestParam String key, @RequestParam String value) {
|
|
|
+ //redisTemplate.opsForValue().set(key, value);
|
|
|
+ redissonClient.getBucket(key).set(value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/hget")
|
|
|
+ public Object hget(@RequestParam String[] key, @RequestParam String hashKey) {
|
|
|
+ //return redisTemplate.opsForHash().multiGet(hashKey, Arrays.asList(key));
|
|
|
+ return redissonClient.getMap(hashKey).getAll(new HashSet<>(Arrays.asList(key)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/hput")
|
|
|
+ public Object hput(@RequestParam String hashKey, @RequestParam String[] key, @RequestParam String[] value) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < key.length; i++) {
|
|
|
+ map.put(key[i], value[i]);
|
|
|
+ }
|
|
|
+ // redisTemplate.opsForHash().putAll(hashKey, map);
|
|
|
+ redissonClient.getMap(hashKey).putAll(map);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|