|
|
@ -3,8 +3,11 @@ package com.mashibing.cache.controller;
|
|
|
|
import com.msb.framework.redis.RedisClient;
|
|
|
|
import com.msb.framework.redis.RedisClient;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
@ -20,6 +23,9 @@ public class CacheController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisClient redisClient;
|
|
|
|
private RedisClient redisClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/cache/hmset/{key}")
|
|
|
|
@PostMapping(value = "/cache/hmset/{key}")
|
|
|
|
public void hmset(@PathVariable(value = "key") String key, @RequestBody Map<String, Object> map) {
|
|
|
|
public void hmset(@PathVariable(value = "key") String key, @RequestBody Map<String, Object> map) {
|
|
|
|
log.info("【缓存模块】 hmset方法,存储key = {},存储value = {}", key, map);
|
|
|
|
log.info("【缓存模块】 hmset方法,存储key = {},存储value = {}", key, map);
|
|
|
@ -44,6 +50,19 @@ public class CacheController {
|
|
|
|
redisClient.sAdd(key,value);
|
|
|
|
redisClient.sAdd(key,value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/cache/sinterstr/{key}/{sinterKey}")
|
|
|
|
|
|
|
|
public Set<Object> sinterStr(@PathVariable(value = "key")String key, @PathVariable String sinterKey,@RequestBody String... value){
|
|
|
|
|
|
|
|
log.info("【缓存模块】 sinterStr的交集方法,存储key = {},sinterKey = {},存储value = {}", key, sinterKey,value);
|
|
|
|
|
|
|
|
//1、 存储数据到set集合
|
|
|
|
|
|
|
|
redisClient.sAdd(key,value);
|
|
|
|
|
|
|
|
//2、 需要将key和sinterKey做交集操作,并拿到返回的set
|
|
|
|
|
|
|
|
Set<Object> result = redisTemplate.opsForSet().intersect(key, sinterKey);
|
|
|
|
|
|
|
|
//3、 将key删除
|
|
|
|
|
|
|
|
redisClient.delete(key);
|
|
|
|
|
|
|
|
//4、 返回交集结果
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/cache/hgetall/{key}")
|
|
|
|
@GetMapping("/cache/hgetall/{key}")
|
|
|
|
public Map hGetAll(@PathVariable(value = "key")String key){
|
|
|
|
public Map hGetAll(@PathVariable(value = "key")String key){
|
|
|
|