Closed musclechen closed 2 years ago
@cyfckl2012 thanks for the effort and apologies for delayed response, but I am not sure I like what I see :)
First of all, it's too many things in one PR. The other problem for me is that the code is not very clean. You still have debug (fmt.Println
) there and some methods (e.g. pubsub
and watchDog
) are almost unreadable.
I also have a hard time to fully understand why this implementation is better/faster/less contentious. I cannot see how it would improve real-world applications even in ultra-low-latency scenarios. But, that takes us back to my initial "too many things in one PR" comment. I would really appreciate if you could submit multiple, smaller PRs with one feature each, then we can discuss the code one step at a time.
Thanks again for the contribution, but I will decline this PR for now, since it's not in a ready-to-merge state (yet).
Modified content:
Existing problems: Maybe using go-test will display "use of closed network connection", but if you use the Gin framework to introduce distributed locks, there will be no similar problems. I have used Jmeter for testing and there are no similar problems.
Problem analysis: Each goroutine did not immediately execute "defer pub.Unsubscribe(ctx, key+"-pub")" on line 494 after the execution was completed, but waited until the main thread ended before executing this line of code, but after the main thread ended the redis link is closed.
The distributed lock borrows Java's Redisson implementation. Welcome to point out the unreasonable points. I will try my best to modify it. I look forward to the code can be merged into the main branch, and I will contribute my own strength to GitHub.