| | |
| | | package com.ks.lijin.controller; |
| | | |
| | | import com.ks.lijin.exception.LiJinException; |
| | | import com.google.gson.Gson; |
| | | import com.ks.vip.pojo.DO.VipGrade; |
| | | import com.ks.vip.pojo.Enums.VIPEnum; |
| | | import com.ks.vip.service.VipGradeService; |
| | | import org.apache.dubbo.config.annotation.Reference; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Reference(version = "1.0") |
| | | private VipGradeService vipGradeService; |
| | | |
| | | @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, "服务器繁忙,请稍后再试"); |
| | | try { |
| | | if (redisTemplate.opsForValue().setIfAbsent(key, "1", 120, TimeUnit.SECONDS)) { |
| | | return "锁定成功"; |
| | | } else { |
| | | return "服务器繁忙,请稍后再试"; |
| | | } |
| | | } finally { |
| | | redisTemplate.delete(key); |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("vip") |
| | | public String testVip(String uid) throws Exception { |
| | | VipGrade grade = vipGradeService.getByVipEnum(VIPEnum.platinum); |
| | | return new Gson().toJson(grade); |
| | | } |
| | | |
| | | } |