| | |
| | | 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; |
| | |
| | | @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, "服务器繁忙,请稍后再试"); |
| | | try { |
| | | if (redisTemplate.opsForValue().setIfAbsent(key, "1", 120, TimeUnit.SECONDS)) { |
| | | return "锁定成功"; |
| | | } else { |
| | | return "服务器繁忙,请稍后再试"; |
| | | } |
| | | } finally { |
| | | redisTemplate.delete(key); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |