package com.ks.lijin.controller;
|
|
import com.ks.lijin.exception.LiJinException;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import java.util.concurrent.TimeUnit;
|
|
@Controller
|
@RequestMapping("test")
|
public class TestController {
|
|
@Resource
|
private RedisTemplate redisTemplate;
|
|
@ResponseBody
|
@RequestMapping("redis")
|
public String testRedis(String uid) throws Exception {
|
String key = "createtblijin-" + uid;
|
if (redisTemplate.opsForValue().setIfAbsent(key, "1", 120, TimeUnit.SECONDS)) {
|
return "锁定成功";
|
} else {
|
throw new LiJinException(LiJinException.CODE_SERVER_BUSY, "服务器繁忙,请稍后再试");
|
}
|
|
}
|
|
}
|