分布式锁解决不同集群的问题

lua脚本解决原子性问题
This commit is contained in:
fang 2025-03-21 19:57:46 +08:00
parent 7722dd11b9
commit 2ed23fc89f
6 changed files with 165 additions and 4 deletions

View File

@ -14955,3 +14955,46 @@
127.0.0.1 - - [19/Mar/2025:20:24:58 +0800] "GET /api/shop/1 HTTP/1.1" 200 713 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0" 127.0.0.1 - - [19/Mar/2025:20:24:58 +0800] "GET /api/shop/1 HTTP/1.1" 200 713 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [19/Mar/2025:20:24:58 +0800] "GET /api/voucher/list/1 HTTP/1.1" 200 530 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0" 127.0.0.1 - - [19/Mar/2025:20:24:58 +0800] "GET /api/voucher/list/1 HTTP/1.1" 200 530 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [19/Mar/2025:20:25:00 +0800] "POST /api/voucher-order/seckill/10 HTTP/1.1" 200 53 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0" 127.0.0.1 - - [19/Mar/2025:20:25:00 +0800] "POST /api/voucher-order/seckill/10 HTTP/1.1" 200 53 "http://localhost:8080/shop-detail.html?id=1" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:07 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:08 +0800] "GET /api/shop-type/list HTTP/1.1" 499 0 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:10 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:13 +0800] "GET /api/user/me HTTP/1.1" 401 0 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:13 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:13 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:21 +0800] "POST /api/user/code?phone=13686869696 HTTP/1.1" 200 27 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:34 +0800] "POST /api/user/login HTTP/1.1" 200 69 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:34 +0800] "GET /api/shop-type/list HTTP/1.1" 200 664 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:34 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:34 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:36 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:36 +0800] "GET /api/user/me HTTP/1.1" 200 100 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:36 +0800] "GET /api/blog/of/me HTTP/1.1" 200 673 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:36 +0800] "GET /api/user/info/1 HTTP/1.1" 200 27 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:39 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:39 +0800] "GET /api/shop-type/list HTTP/1.1" 200 664 "http://localhost:8080/" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:34:39 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:35:53 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:35:53 +0800] "GET /api/user/me HTTP/1.1" 401 0 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:35:53 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:35:55 +0800] "POST /api/user/code?phone=13686869696 HTTP/1.1" 200 27 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:36:15 +0800] "POST /api/user/login HTTP/1.1" 200 69 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:36:15 +0800] "GET /api/shop-type/list HTTP/1.1" 200 664 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:36:15 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:15:36:15 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:48 +0800] "GET /index.html HTTP/1.1" 304 0 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:48 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:48 +0800] "GET /favicon.ico HTTP/1.1" 200 6343 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:49 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:49 +0800] "GET /api/shop-type/list HTTP/1.1" 200 664 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:49 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:49 +0800] "GET /api/user/me HTTP/1.1" 401 0 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:49 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:30:53 +0800] "POST /api/user/code?phone=13686869696 HTTP/1.1" 499 0 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:02 +0800] "POST /api/user/login HTTP/1.1" 200 69 "http://localhost:8080/login.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:02 +0800] "GET /api/shop-type/list HTTP/1.1" 200 664 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:02 +0800] "GET /api/blog/hot?current=1 HTTP/1.1" 200 6065 "http://localhost:8080/index.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:02 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:03 +0800] "GET /js/axios.min.map HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:03 +0800] "GET /api/user/me HTTP/1.1" 200 100 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:03 +0800] "GET /api/user/info/1 HTTP/1.1" 200 27 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"
127.0.0.1 - - [20/Mar/2025:20:31:03 +0800] "GET /api/blog/of/me HTTP/1.1" 200 673 "http://localhost:8080/info.html" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/134.0.0.0"

View File

@ -2855,3 +2855,17 @@
2025/03/19 20:24:56 [error] 13588#22156: *58 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080" 2025/03/19 20:24:56 [error] 13588#22156: *58 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/19 20:24:57 [error] 13588#22156: *64 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080" 2025/03/19 20:24:57 [error] 13588#22156: *64 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/19 20:24:58 [error] 13588#22156: *64 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080" 2025/03/19 20:24:58 [error] 13588#22156: *64 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:10 [error] 13588#22156: *72 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:13 [error] 13588#22156: *72 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:13 [error] 13588#22156: *72 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:34 [error] 13588#22156: *78 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:36 [error] 13588#22156: *86 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:34:39 [error] 13588#22156: *90 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:35:53 [error] 13588#22156: *94 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:35:53 [error] 13588#22156: *93 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 15:36:15 [error] 13588#22156: *98 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 20:30:48 [error] 13588#22156: *105 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 20:30:49 [error] 13588#22156: *105 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 20:30:49 [error] 13588#22156: *106 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 20:31:02 [error] 13588#22156: *116 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"
2025/03/20 20:31:03 [error] 13588#22156: *116 CreateFile() "D:\Program Files\java_program\hm-dianping\nginx-1.18.0/html/hmdp/js/axios.min.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /js/axios.min.map HTTP/1.1", host: "localhost:8080"

View File

@ -11,13 +11,16 @@ import com.hmdp.service.IVoucherOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.service.IVoucherService; import com.hmdp.service.IVoucherService;
import com.hmdp.utils.RedisIdWorker; import com.hmdp.utils.RedisIdWorker;
import com.hmdp.utils.SimpleRedisLock;
import com.hmdp.utils.UserHolder; import com.hmdp.utils.UserHolder;
import org.springframework.aop.framework.AopContext; import org.springframework.aop.framework.AopContext;
import org.springframework.aop.framework.AopProxy; import org.springframework.aop.framework.AopProxy;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -34,6 +37,8 @@ public class VoucherOrderServiceImpl extends ServiceImpl<VoucherOrderMapper, Vou
private ISeckillVoucherService iSeckillVoucherService; private ISeckillVoucherService iSeckillVoucherService;
@Autowired @Autowired
private RedisIdWorker redisIdWorker; private RedisIdWorker redisIdWorker;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override @Override
public Result seckillVoucher(Long voucherId) { public Result seckillVoucher(Long voucherId) {
@ -50,11 +55,27 @@ public class VoucherOrderServiceImpl extends ServiceImpl<VoucherOrderMapper, Vou
return Result.fail("库存不足"); return Result.fail("库存不足");
} }
Long userID = UserHolder.getUser().getId(); Long userID = UserHolder.getUser().getId();
synchronized(userID.toString().intern()) {
// // 基于悲观锁但是这个在集群环境下还是会导致线程不安全
// synchronized(userID.toString().intern()) {
// // 获取代理对象才能让事务生效
// IVoucherOrderService proxy = (IVoucherOrderService) AopContext.currentProxy();
// return proxy.creatVoucheOrder(voucherId);
// }
SimpleRedisLock simpleRedisLock = new SimpleRedisLock("oreder:" + userID, stringRedisTemplate);
boolean isLock = simpleRedisLock.tryLock(1200L);
if(!isLock){
return Result.fail("请勿重复下单");
}
// 获取代理对象才能让事务生效 // 获取代理对象才能让事务生效
try {
IVoucherOrderService proxy = (IVoucherOrderService) AopContext.currentProxy(); IVoucherOrderService proxy = (IVoucherOrderService) AopContext.currentProxy();
return proxy.creatVoucheOrder(voucherId); return proxy.creatVoucheOrder(voucherId);
} finally {
// 释放锁
simpleRedisLock.unLock();
} }
} }
@Transactional @Transactional
public Result creatVoucheOrder(Long voucherId) { public Result creatVoucheOrder(Long voucherId) {

View File

@ -0,0 +1,7 @@
package com.hmdp.utils;
public interface ILock {
boolean tryLock(Long timeOutSec);
void unLock();
}

View File

@ -0,0 +1,61 @@
package com.hmdp.utils;
import cn.hutool.core.lang.UUID;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
public class SimpleRedisLock implements ILock {
private String name;
private StringRedisTemplate stringRedisTemplate;
private static final String KEY_PREFIX = "lock:";
private static final String ID_PREFIX = UUID.randomUUID().toString(true)+"-";
private static final DefaultRedisScript<Long> UNLOCK_SCRIPT;
// 通过静态代码块在类初始化的时候就创建了lua脚本
static {
UNLOCK_SCRIPT = new DefaultRedisScript<>();
UNLOCK_SCRIPT.setLocation(new ClassPathResource("unlock.lua"));
UNLOCK_SCRIPT.setResultType(Long.class);
}
public SimpleRedisLock(String name, StringRedisTemplate stringRedisTemplate) {
this.name = name;
this.stringRedisTemplate = stringRedisTemplate;
}
@Override
public boolean tryLock(Long timeOutSec) {
// 获取当前线程id
String threadId = ID_PREFIX+Thread.currentThread().getId();
Boolean succed = stringRedisTemplate.opsForValue().setIfAbsent(KEY_PREFIX + name, threadId , timeOutSec, TimeUnit.SECONDS);
return Boolean.TRUE.equals(succed);
}
@Override
// // 这种实现方法不能保证原子性
// public void unLock() {
// // 释放锁直接删除就好了
// // 但是直接删除又会存在一个问题就是有可能删除的不是自己的锁所以需要判断
// String threadId = ID_PREFIX+Thread.currentThread().getId();
// String id = stringRedisTemplate.opsForValue().get(KEY_PREFIX + name);
// if(id.equals(threadId)) {
// stringRedisTemplate.delete(KEY_PREFIX + name);
// }
// }
public void unLock() {
// 调用lua脚本
stringRedisTemplate.execute(
UNLOCK_SCRIPT,
Collections.singletonList(KEY_PREFIX+name),
ID_PREFIX+Thread.currentThread().getId()
);
}
}

View File

@ -0,0 +1,15 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by fang.
--- DateTime: 2025/3/21 16:27
---
--- 获取redis中存的id
--- 获取UUID+当前线程id,通过参数传进来
if(redis.call("get", KEYS[1])==ARGV[1]) then
--- 一致删除锁并放回1
return redis.call("del", KEYS[1])
end
--- 不一致返回0
return 0