package com.sinata.zuul.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.sinata.zuul.util.RedisUtil;
|
import com.sinata.zuul.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 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());
|
}
|
}
|