RedisLockController.java 884 B

1234567891011121314151617181920212223242526272829303132333435
  1. package com.ruoyi.demo.controller;
  2. import com.ruoyi.common.annotation.RedisLock;
  3. import com.ruoyi.common.core.domain.AjaxResult;
  4. import org.springframework.web.bind.annotation.GetMapping;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. /**
  8. * 测试分布式锁的样例
  9. *
  10. * @author shenxinquan
  11. */
  12. @RestController
  13. @RequestMapping("/demo/redisLock")
  14. public class RedisLockController {
  15. /**
  16. * #p0 标识取第一个参数为redis锁的key
  17. */
  18. @GetMapping("/getLock")
  19. @RedisLock(expireTime = 10, key = "#p0")
  20. public AjaxResult<String> getLock(String key, String value) {
  21. try {
  22. // 同时请求排队
  23. // Thread.sleep(5000);
  24. // 锁超时测试
  25. Thread.sleep(11000);
  26. } catch (InterruptedException e) {
  27. e.printStackTrace();
  28. }
  29. return AjaxResult.success("操作成功",value);
  30. }
  31. }