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 keys
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getValues")
|
public String getValues(String keys){
|
String[] split = keys.split(",");
|
List<String> list = Arrays.asList(split);
|
List<Object> values = redisUtil.getValues(list);
|
return JSON.toJSONString(ResultUtil.success(values));
|
}
|
|
|
/**
|
* 存值
|
* @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());
|
}
|
|
|
/**
|
* 添加数据到list集合
|
* @param key
|
* @param s
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/addValueList")
|
public String addValueList(String key, String value){
|
redisUtil.addValueList(key, value);
|
return JSON.toJSONString(ResultUtil.success());
|
}
|
|
|
/**
|
* 集合中获取数据
|
* @param key
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getValueList")
|
public String getValueList(String key){
|
String valueList = redisUtil.getValueList(key);
|
return JSON.toJSONString(ResultUtil.success(valueList));
|
}
|
|
|
/**
|
* 删除集合数据
|
* @param key
|
* @param count
|
* @param value
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/delValueList")
|
public String delValueList(String key, long count, String value){
|
redisUtil.delValueList(key, count, value);
|
return JSON.toJSONString(ResultUtil.success());
|
}
|
|
|
/**
|
* 获取list集合数量
|
* @param key
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getListCount")
|
public String getListCount(String key){
|
Long length = redisUtil.getListCount(key);
|
return JSON.toJSONString(ResultUtil.success(length));
|
}
|
|
|
/**
|
* 获取list集合数据
|
* @param key
|
* @param start
|
* @param end
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getList")
|
public String getList(String key, Long start, Long end){
|
List<String> list = redisUtil.getList(key, start, end);
|
return JSON.toJSONString(ResultUtil.success(list));
|
}
|
|
|
/**
|
* 获取list集合所有数据
|
* @param key
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getAllList")
|
public String getAllList(String key){
|
List<String> list = redisUtil.getAllList(key);
|
return JSON.toJSONString(ResultUtil.success(list));
|
}
|
}
|