-
Notifications
You must be signed in to change notification settings - Fork 1
/
redisson-lock.drawio
872 lines (872 loc) · 225 KB
/
redisson-lock.drawio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
<mxfile host="Electron" modified="2024-05-16T12:46:53.888Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.6.5 Chrome/114.0.5735.243 Electron/25.3.1 Safari/537.36" etag="VzOSeL7ugwU1zWIOePUC" version="21.6.5" type="device" pages="3">
<diagram name="RedissonLock" id="BnpH6MyAiMC-jk9W1z5V">
<mxGraphModel dx="3915" dy="879" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="LtS7gfKAsIHDJF8mLO0w-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=-0.001;entryY=0.565;entryDx=0;entryDy=0;fillColor=#dae8fc;strokeColor=#6c8ebf;entryPerimeter=0;" edge="1" parent="1" source="LtS7gfKAsIHDJF8mLO0w-1" target="dYNV18oPOYucMmK5HlVg-50">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="3070" y="1910" />
<mxPoint x="3070" y="904" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-86" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.75;entryDx=0;entryDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-83" target="dYNV18oPOYucMmK5HlVg-46" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="2840" y="1730" as="targetPoint" />
<Array as="points">
<mxPoint x="3050" y="1730" />
<mxPoint x="3050" y="685" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-94" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-86" vertex="1" connectable="0">
<mxGeometry x="-0.9752" y="2" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-75" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=1.002;entryY=0.838;entryDx=0;entryDy=0;entryPerimeter=0;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="dYNV18oPOYucMmK5HlVg-64" target="dYNV18oPOYucMmK5HlVg-26" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-76" value="唤醒" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-75" vertex="1" connectable="0">
<mxGeometry x="-0.9524" y="-3" relative="1" as="geometry">
<mxPoint y="1" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dfN3vujWDwPQzVs5uhvx-1" value="<h1 style="font-size: 18px;"><font style="font-size: 18px;">Redisson 分布式锁工作原理流程</font></h1><div style="font-size: 12px;"><div style=""><font style="font-size: 12px;">源码版本:3.29.0</font></div></div><div style="font-size: 12px;">测试DEMO: SpringBoot-Labs/redis/redisson/redisson-exampl<span style="background-color: initial;">e</span></div><div style="font-size: 12px;"><span style="background-color: initial;"><br></span></div><div style="font-size: 12px;"><span style="background-color: initial;">RedissonLock的实现依赖<b>Redis发布订阅</b>,所以研究分布式锁的源码前最好先看下Redisson发布订阅的实现。</span></div>" style="text;html=1;strokeColor=none;fillColor=none;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;rounded=0;fontSize=16;" parent="1" vertex="1">
<mxGeometry x="40" y="10" width="680" height="110" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-1" target="IO7cbxsnxIBy7bkgTzKg-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-1" value="RedissonLock" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="40" y="160" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-2" target="IO7cbxsnxIBy7bkgTzKg-4" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-2" value="RedissonLockTest#<br style="font-size: 11px;">testSubscriptionsPerConnection()" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="280" y="160" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-4" target="IO7cbxsnxIBy7bkgTzKg-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-9" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-4" target="IO7cbxsnxIBy7bkgTzKg-8" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-4" value="先创建连接配置" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="160" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-13" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-6" target="IO7cbxsnxIBy7bkgTzKg-12" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-15" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-6" target="IO7cbxsnxIBy7bkgTzKg-14" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-6" value="根据连接配置创建客户端连接" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="260" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-8" value="<div style="font-size: 10px;"><font color="#007fff">//创建最基本的连接配置(RESP2协议、服务器地址redis://127.0.0.1:6379)</font></div><div style="font-size: 10px;">Config config = createConfig();&nbsp;</div><div style="font-size: 10px;">config.useSingleServer()</div><div style="font-size: 10px;">.setSubscriptionConnectionPoolSize(1) <font color="#007fff">//订阅连接池的大小</font></div><div style="font-size: 10px;">.setSubscriptionConnectionMinimumIdleSize(1)</div><div style="font-size: 10px;">.setSubscriptionsPerConnection(1) <font color="#007fff">//每个连接限制订阅的数量</font></div><div style="font-size: 10px;">.setAddress(redisson.getConfig().useSingleServer().getAddress());</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=10;" parent="1" vertex="1">
<mxGeometry x="760" y="140" width="360" height="100" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-12" value="RedissonClient redisson&nbsp; = Redisson.<b>create</b>(config);<br><font color="#007fff">这个看发布订阅流程图中的分析,主要是创建连接和线程池</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="760" y="260" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-17" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-14" target="IO7cbxsnxIBy7bkgTzKg-16" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-14" value="ExecutorService e = Executors.newFixedThreadPool(32);<br><font color="#007fff">创建了包含32个线程的线程池,模拟并发请求</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="360" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-19" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;dashed=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-16" target="IO7cbxsnxIBy7bkgTzKg-18" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-16" value="for 循环5000次,向线程池中提交分布锁同步的任务,每个任务随机睡眠0-20ms模拟业务处理耗时" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-21" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-18" target="IO7cbxsnxIBy7bkgTzKg-22" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="1160" y="470" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-27" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="IO7cbxsnxIBy7bkgTzKg-21" vertex="1" connectable="0">
<mxGeometry x="0.75" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-25" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-18" target="IO7cbxsnxIBy7bkgTzKg-23" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-28" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="IO7cbxsnxIBy7bkgTzKg-25" vertex="1" connectable="0">
<mxGeometry x="0.35" y="2" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-26" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-18" target="IO7cbxsnxIBy7bkgTzKg-24" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1140" y="470" />
<mxPoint x="1140" y="1630" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-29" value="3" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="IO7cbxsnxIBy7bkgTzKg-26" vertex="1" connectable="0">
<mxGeometry x="0.8" y="-2" relative="1" as="geometry">
<mxPoint x="2" y="100" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-18" value="<div style="font-size: 10px;">try {</div><div style="font-size: 10px;"><span style="background-color: initial;">&nbsp; &nbsp; String lockKey = "lock-1";</span><br></div><div style="font-size: 10px;">&nbsp; &nbsp; RLock lock = redisson.<b>getLock</b>(lockKey); <font color="#007fff">//1</font></div><div style="font-size: 10px;">&nbsp; &nbsp; lock.<b>lock</b>(); <font color="#007fff">//2</font></div><div style="font-size: 10px;">&nbsp; &nbsp; Thread.sleep(ThreadLocalRandom.current().nextInt(20));</div><div style="font-size: 10px;">&nbsp; &nbsp; counter++;</div><div style="font-size: 10px;">&nbsp; &nbsp; lock.<b>unlock</b>(); <font color="#007fff">//3</font></div><div style="font-size: 10px;">&nbsp; &nbsp; ops.incrementAndGet();</div><div style="font-size: 10px;">} catch (Exception exception) {</div><div style="font-size: 10px;">&nbsp; &nbsp; exception.printStackTrace();</div><div style="font-size: 10px;">&nbsp; &nbsp; if(exception instanceof RedisTimeoutException){</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; return;</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; errors.incrementAndGet();</div><div style="font-size: 10px;">}</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="760" y="380" width="360" height="180" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-33" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-22" target="IO7cbxsnxIBy7bkgTzKg-32" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-22" value="<div>RLock lock = redisson.getLock(lockKey);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="1160" y="360" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-29" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-23" target="dYNV18oPOYucMmK5HlVg-28" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-23" value="<div>&nbsp; &nbsp; lock.lock();</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="1160" y="440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-78" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-24" target="dYNV18oPOYucMmK5HlVg-77" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-24" value="<div>&nbsp; &nbsp; lock.un<span style="background-color: initial;">lock();</span></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="1160" y="1600" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-15" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-32" target="dYNV18oPOYucMmK5HlVg-14" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-32" value="<div>return new <b>RedissonLock</b>(<br>this.commandExecutor, name);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="1400" y="360" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-24" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-34" target="IO7cbxsnxIBy7bkgTzKg-36" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-13" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;dashed=1;endArrow=block;endFill=1;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-34" target="dYNV18oPOYucMmK5HlVg-12" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-63" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=-0.002;exitY=0.646;exitDx=0;exitDy=0;entryX=1;entryY=0.286;entryDx=0;entryDy=0;entryPerimeter=0;exitPerimeter=0;endArrow=open;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-34" target="dYNV18oPOYucMmK5HlVg-20" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="-460" y="1141" />
<mxPoint x="-460" y="1300" />
<mxPoint x="-900" y="1300" />
<mxPoint x="-900" y="1526" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-34" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonBaseLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">锁相关对象的基本抽象类,锁相关的大部分类都继承此抽象类</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">private static final ConcurrentMap&lt;String, ExpirationEntry&gt; <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><b>EXPIRATION_RENEWAL_MAP</b> = new ConcurrentHashMap();</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//锁超时释放时间ms(看门狗超时时间), 对应配置类中的 lockWatchdogTimeout</font></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//默认30s</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected long <b>internalLockLeaseTime</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对应的ServiceManager id (是UUID), 可能后面逻辑哪里可能需要获取ServiceManager</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final String <b>id</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//id + ":" + name</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final String <b>entryName</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//来自Redisson commandExecutor</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final CommandAsyncExecutor <b>commandExecutor</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">private static final RedisCommand&lt;Integer&gt; <b>HGET</b> = new <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>RedisCommand("HGET", new MapValueDecoder(), new <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>IntegerReplayConvertor(0));</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-440" y="960" width="400" height="280" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-25" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-35" target="IO7cbxsnxIBy7bkgTzKg-34" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-17" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.801;entryDx=0;entryDy=0;entryPerimeter=0;endArrow=open;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-35" target="dYNV18oPOYucMmK5HlVg-16" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="-460" y="1400" />
<mxPoint x="-460" y="1705" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-35" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><b>基本的可重入锁实现</b></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//锁超时释放时间ms(看门狗超时时间), 对应配置类中的 lockWatchdogTimeout</font></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//默认30s</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected long <b style="background-color: initial;">internalLockLeaseTime</b><span style="background-color: initial;">;</span><br></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><font color="#007fff">//来自PublishSubscribeService lockPubSub</font></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final <b>LockPubSub</b> <b>pubSub</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final CommandAsyncExecutor <b>commandExecutor</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-440" y="1280" width="400" height="160" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-36" target="IO7cbxsnxIBy7bkgTzKg-37" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-7" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.25;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;dashed=1;fontSize=11;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-36" target="IO7cbxsnxIBy7bkgTzKg-42" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="-340" y="780" />
<mxPoint x="-620" y="780" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-36" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonExpirable (A)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="color: rgb(0, 127, 255); background-color: initial;">拓展超时方法实现,由于Redisson大部分对象都需要支持超时方法,</span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="color: rgb(0, 127, 255); background-color: initial;">Redisson大部分对象类都继承此类</span></p><div style="font-size: 11px;"><br style="font-size: 11px;"></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-440" y="800" width="400" height="120" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-5" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;dashed=1;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-37" target="IO7cbxsnxIBy7bkgTzKg-39" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-12" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.25;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;endArrow=open;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-37" target="UIfJx8McfHb-EtYyFKPk-9" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="-460" y="640" />
<mxPoint x="-460" y="280" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-37" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonObject (A)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//命令异步执行器,其实封装了</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final <b>CommandAsyncExecutor</b> <b>commandExecutor</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对象名字</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected String <b>name</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对象使用的编解码器</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final Codec <b>codec</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="-440" y="600" width="400" height="160" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-3" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-39" target="IO7cbxsnxIBy7bkgTzKg-40" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-39" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RObject (I)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">定义Redisson对象的基本方法(这里定义同步方法),Redisson对象的核心接口,Redisson所有对象都实现此接口<br></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><br></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//获取对象空闲时间(s),即从上次读写到现在的秒数</font></p><p style="margin: 0px 0px 0px 4px;">Long getIdleTime();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//更新对象最后访问时间</font></p><p style="margin: 0px 0px 0px 4px;">boolean touch();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//对象在Redis中占用内存大小(按bytes计算)</font></p><p style="margin: 0px 0px 0px 4px;">long sizeInMemory();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//Redisson对象的一些序列化和反序列化方法</font></p><p style="margin: 0px 0px 0px 4px;">void restore(byte[] state);</p><p style="margin: 0px 0px 0px 4px;">...</p><p style="margin: 0px 0px 0px 4px;">byte[] dump();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//对象迁移、复制</font></p><p style="margin: 0px 0px 0px 4px;">void migrate(String host, int port, int database, long timeout);<br></p><p style="margin: 0px 0px 0px 4px;">void copy(String host, int port, int database, long timeout);<br></p><p style="margin: 0px 0px 0px 4px;">boolean move(int database);<br style="font-size: 11px;"></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//对象基本操作方法</font></p><p style="margin: 0px 0px 0px 4px;">String getName();<br></p><p style="margin: 0px 0px 0px 4px;">boolean delete();<br></p><p style="margin: 0px 0px 0px 4px;">boolean unlink();<br></p><p style="margin: 0px 0px 0px 4px;">void rename(String newName);<br></p><p style="margin: 0px 0px 0px 4px;">boolean renamenx(String newName);<br></p><p style="margin: 0px 0px 0px 4px;">boolean isExists();<br></p><p style="margin: 0px 0px 0px 4px;">Codec getCodec();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//对象监听器相关,具体参考各种监听器实现类</font></p><p style="margin: 0px 0px 0px 4px;">int addListener(ObjectListener listener);<br></p><p style="margin: 0px 0px 0px 4px;">void removeListener(int listenerId);<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-440" y="160" width="400" height="400" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-40" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RObjectAsync (I)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff" style="font-size: 11px;">拓展 RObject&nbsp;<b>异步</b>接口方法,返回 RFuture</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-440" y="40" width="240" height="80" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-1" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-41" target="IO7cbxsnxIBy7bkgTzKg-40" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-41" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RExpirableAsync (I)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">拓展 RExpirable 异步接口方法,返回 RFuture</font></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-760" y="160" width="280" height="80" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;fontSize=11;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-42" target="IO7cbxsnxIBy7bkgTzKg-41" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-8" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;" parent="1" source="IO7cbxsnxIBy7bkgTzKg-42" target="IO7cbxsnxIBy7bkgTzKg-39" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="IO7cbxsnxIBy7bkgTzKg-42" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RExpirable (I)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">为对象定义超时方法(TTL)</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p><p style="margin: 0px 0px 0px 4px;">boolean expire(Instant time);<br></p><p style="margin: 0px 0px 0px 4px;">boolean expireIfSet(Instant time);<br></p><p style="margin: 0px 0px 0px 4px;">...</p><p style="margin: 0px 0px 0px 4px;">boolean expire(Duration duration);<br></p><p style="margin: 0px 0px 0px 4px;">...</p><p style="margin: 0px 0px 0px 4px;">boolean clearExpire();<br></p><p style="margin: 0px 0px 0px 4px;">long remainTimeToLive();<br></p><p style="margin: 0px 0px 0px 4px;">long getExpireTime();<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-760" y="600" width="280" height="160" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-9" value="<div style="text-align: center;"><b>CommandAsyncExecutor</b><b style="background-color: initial;">&nbsp;(I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">Redis命令异步执行器,Redisson提供了异步、批量异步、响应式(基于Reactor、RxJava)多种实现</font></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-1120" y="240" width="240" height="80" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-11" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;dashed=1;" parent="1" source="UIfJx8McfHb-EtYyFKPk-20" target="UIfJx8McfHb-EtYyFKPk-9" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="-1000" y="360" as="sourcePoint" />
</mxGeometry>
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-23" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.001;exitY=0.439;exitDx=0;exitDy=0;endArrow=open;endFill=0;exitPerimeter=0;" parent="1" source="UIfJx8McfHb-EtYyFKPk-20" target="dYNV18oPOYucMmK5HlVg-7" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="-1240" y="450" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-20" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>CommandAsyncService</b><br></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;"><font color="#007fff"><b>异步执行器实现,其他几种执行器全都继承这个类,说明所有执行器都是异步的</b></font></p><p style="margin: 0px 0px 0px 4px;"><br></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">final Codec codec;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font style="border-color: var(--border-color);" color="#007fff">//连接管理器,就是保存连接的容器类对象</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">final&nbsp;<b style="border-color: var(--border-color);">ConnectionManager</b>&nbsp;<b style="border-color: var(--border-color);">connectionManager</b>;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">final RedissonObjectBuilder objectBuilder;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">final RedissonObjectBuilder.ReferenceType referenceType;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final int retryAttempts;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final int retryInterval;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final int responseTimeout;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final boolean trackChanges;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-1200" y="360" width="400" height="200" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-22" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;" parent="1" source="UIfJx8McfHb-EtYyFKPk-21" target="UIfJx8McfHb-EtYyFKPk-20" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-21" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>CommandBatchService</b><br></p><hr style="font-size: 11px;"><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font style="border-color: var(--border-color);" color="#007fff">批量执行器实现(也是异步的)</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><br style="border-color: var(--border-color);"></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final AtomicInteger index = new AtomicInteger();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;NodeSource, Entry&gt;&nbsp;<b style="border-color: var(--border-color);">commands</b>&nbsp;= new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private Map&lt;MasterSlaveEntry, Entry&gt;&nbsp;<b style="border-color: var(--border-color);">aggregatedCommands</b>&nbsp;= Collections.emptyMap();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;MasterSlaveEntry, ConnectionEntry&gt;&nbsp;<b style="border-color: var(--border-color);">connections</b>&nbsp;= new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final BatchOptions options;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final Map&lt;CompletableFuture&lt;?&gt;, List&lt;CommandBatchService&gt;&gt; nestedServices = new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final AtomicBoolean executed = new AtomicBoolean();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final long retryInterval;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final int retryAttempts;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-1200" y="600" width="400" height="280" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-29" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;" parent="1" source="UIfJx8McfHb-EtYyFKPk-28" target="dYNV18oPOYucMmK5HlVg-9" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="-1440" y="1040" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-28" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>SingleConnectionManager</b><br></p><hr style="font-size: 11px;"><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff">Redis单机模式连接管理器</font></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-1640" y="1080" width="400" height="80" as="geometry" />
</mxCell>
<mxCell id="UIfJx8McfHb-EtYyFKPk-31" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-11" target="dYNV18oPOYucMmK5HlVg-9" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="-1880" y="1080" as="sourcePoint" />
<mxPoint x="-1470" y="1050" as="targetPoint" />
<Array as="points">
<mxPoint x="-1880" y="1061" />
<mxPoint x="-1440" y="1061" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-1" value="Redisson" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1465" y="330" width="70" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-3" value="<div style="font-size: 10px;"><br></div>" style="text;html=1;align=left;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontSize=10;" parent="1" vertex="1">
<mxGeometry x="-910" y="1090" width="20" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-5" target="dYNV18oPOYucMmK5HlVg-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-5" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b>Redisson</b></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;"><font color="#007fff"><b>Redisson客户端实现类</b></font></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;"><br></span></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;"><font color="#007fff">//过期任务调度,间接借助ConnectionManager中的线程执行过期任务</font></span></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">private final EvictionScheduler <b>evictionScheduler</b>;</span></p><p style="margin: 0px 0px 0px 4px; font-size: 10px;"><span style="background-color: initial;"><font style="font-size: 10px;" color="#007fff">//同样间接借助ConnectionManager中的线程执行任务,任务会存储到名为tasks的Map</font></span></p><p style="margin: 0px 0px 0px 4px; font-size: 10px;">private final WriteBehindService <b>writeBehindService</b>;</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//连接管理器</font></p><p style="margin: 0px 0px 0px 4px;">private final ConnectionManager <b>connectionManager</b>;</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//命令异步执行器,是CommandAsyncService实例,借助 ConnectionManager中的线程池和连接实现命令异步发送</font></p><p style="margin: 0px 0px 0px 4px;">private final CommandAsyncExecutor <b>commandExecutor</b>;</p><p style="margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;Class&lt;?&gt;, Class&lt;?&gt;&gt; <b>liveObjectClassCache</b> = new ConcurrentHashMap();</p><p style="margin: 0px 0px 0px 4px;">private final Config <b>config</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-1200" y="1040" width="400" height="240" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-6" value="<div style="text-align: center;"><b>RedissonClient</b><b style="background-color: initial;">&nbsp;(I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">包括创建连接、关闭连接、获取服务节点信息,以及获取各种<b>Redisson对象</b>的方法。</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-1120" y="920" width="240" height="80" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-7" value="<div style="text-align: center;"><b>ConnectionManager</b><b style="background-color: initial;">&nbsp;(I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">连接管理器</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><br></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//部分关键接口方法</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//其实是启动Netty客户端</font></p><p style="margin: 0px 0px 0px 4px;">void <b>connect</b>();<br></p><p style="margin: 0px 0px 0px 4px;">void shutdown();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//获取发布订阅服务</font></p><p style="margin: 0px 0px 0px 4px;">PublishSubscribeService getSubscribeService();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//集群模式计算槽位</font></p><p style="margin: 0px 0px 0px 4px;">int calcSlot(String key);<br></p><p style="margin: 0px 0px 0px 4px;">...</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//主从服务节点Entry集合</font></p><p style="margin: 0px 0px 0px 4px;">Collection&lt;MasterSlaveEntry&gt; getEntrySet();<br></p><p style="margin: 0px 0px 0px 4px;">...</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//创建Redis连接(RedisClient)</font></p><p style="margin: 0px 0px 0px 4px;">RedisClient <b>createClient</b>(NodeType type, InetSocketAddress address, RedisURI uri, String sslHostname);<br></p><p style="margin: 0px 0px 0px 4px;">RedisClient <b>createClient</b>(NodeType type, RedisURI address, String sslHostname);</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//<b>ServiceManager</b>(Netty客户端 + ExecutorService + Redis Server 配置)</font></p><p style="margin: 0px 0px 0px 4px;"><b>ServiceManager</b> getServiceManager();<br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//创建命令执行器</font></p><p style="margin: 0px 0px 0px 4px;">CommandAsyncExecutor <b>createCommandExecutor</b>(RedissonObjectBuilder objectBuilder,<span style="background-color: initial;">&nbsp;RedissonObjectBuilder.ReferenceType referenceType);</span></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-1640" y="360" width="400" height="360" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-8" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;dashed=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-9" target="dYNV18oPOYucMmK5HlVg-7" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-9" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>MasterSlaveConnectionManager</b><br></p><hr style="font-size: 11px;"><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff">连接管理器基本实现,其他实现类都继承此实现,包括单机、主从复制</font><font color="#007fff">、哨兵、集群4种实现</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff"><br></font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">protected DNSMonitor dnsMonitor;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">protected MasterSlaveServersConfig <b>config</b>;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff"><b>//连接到Redis服务节点的对象,里面保存连接到某个节点的所有连接对象</b></font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private MasterSlaveEntry <b>masterSlaveEntry</b>;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff"><b>//发布订阅服务</b></font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">protected final PublishSubscribeService <b>subscribeService</b>;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff"><b>//Netty服务器配置等</b></font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">protected final ServiceManager <b>serviceManager</b>;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final Map&lt;RedisURI, RedisConnection&gt; <b>nodeConnections</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">protected final AtomicReference&lt;CompletableFuture&lt;Void&gt;&gt; lazyConnectLatch = new AtomicReference&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private boolean lastAttempt;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="-1640" y="760" width="400" height="280" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-11" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>ClusterConnectionManager</b><br></p><hr style="font-size: 11px;"><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff">Redis集群模式连接管理器</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff"><br></font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final Map&lt;Integer, ClusterPartition&gt; lastPartitions = new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final Map&lt;RedisURI, ClusterPartition&gt; lastUri2Partition = new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private volatile Timeout monitorFuture;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private volatile RedisURI lastClusterNode;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private RedisStrictCommand&lt;List&lt;ClusterNodeInfo&gt;&gt; clusterNodesCommand;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private String configEndpointHostName;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff">//slot对应的服务节点</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final AtomicReferenceArray&lt;MasterSlaveEntry&gt; slot2entry = new AtomicReferenceArray&lt;&gt;(MAX_SLOT);</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"><font color="#007fff">//服务节点也是多个</font></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final Map&lt;RedisClient, MasterSlaveEntry&gt; <b>client2entry</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private ClusterServersConfig cfg;</p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;"></p><p style="border-color: var(--border-color); margin: 0px 0px 0px 4px;">private final long seed = ThreadLocalRandom.current().nextLong();</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-2080" y="1080" width="400" height="320" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-12" value="<div style="text-align: center;"><b>RLock</b><b style="background-color: initial;">&nbsp;(I) </b><span style="background-color: initial;">extends Lock, RLockAsync</span></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">Lock 接口是JUC的接口,RLockAsync是Redisson拓展的<br>异步接口</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">RLock 中额外拓展了一些加锁超时方法。</font></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-760" y="800" width="280" height="120" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-14" value="<div style="font-size: 10px;">super(commandExecutor, name);</div><div style="font-size: 10px;">this.<b style="font-size: 10px;">commandExecutor</b> = commandExecutor;</div><div style="font-size: 10px;">this.<b style="font-size: 10px;">internalLockLeaseTime</b> = getServiceManager().getCfg().getLockWatchdogTimeout();</div><div style="font-size: 10px;"><font color="#007fff">//PublishSubscribeService 实例化时 new LockPubSub(this);</font></div><div style="font-size: 10px;">this.<b style="font-size: 10px;">pubSub</b> = commandExecutor.getConnectionManager()</div><div style="font-size: 10px;"><span style="white-space: pre; font-size: 10px;">	</span>.getSubscribeService().getLockPubSub();</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;" parent="1" vertex="1">
<mxGeometry x="1640" y="350" width="440" height="80" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-68" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.003;exitY=0.796;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;endArrow=open;endFill=0;exitPerimeter=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-16" target="dYNV18oPOYucMmK5HlVg-60" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-16" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>PublishSubscribeService</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><b><font color="#007fff">类似 MasterSlaveEntry 保存了一组用于发布订阅的连接, 通过 Map 存储连接,只不过KEY是发布订阅相关的</font></b></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><br></span></p><p style="margin: 0px 0px 0px 4px;">private final ConnectionManager connectionManager;</p><p style="margin: 0px 0px 0px 4px;">private final MasterSlaveServersConfig config;</p><p style="margin: 0px 0px 0px 4px;">private final AsyncSemaphore[] locks = new AsyncSemaphore[50];</p><p style="margin: 0px 0px 0px 4px;">private final AsyncSemaphore freePubSubLock = new AsyncSemaphore(1);</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//主题名 -&gt; 连接集合</font></p><p style="margin: 0px 0px 0px 4px;">private final Map&lt;<b>ChannelName</b>, Collection&lt;<b>PubSubConnectionEntry</b>&gt;&gt; <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><b>name2entry</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//PubSubKey -&gt; 连接集合<br></font></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//PubSubKey 是 "主题名 + MasterSlaveEntry"</font></p><p style="margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;<b>PubSubKey</b>, PubSubConnectionEntry&gt; <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><b>name2PubSubConnection</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//MasterSlaveEntry -&gt;&nbsp;PubSubEntry</font></p><p style="margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;MasterSlaveEntry, <b>PubSubEntry</b>&gt; <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><b>entry2PubSubConnection</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="margin: 0px 0px 0px 4px;">private final Map&lt;<b>PubSubClientKey</b>, PubSubConnectionEntry&gt;&nbsp;<br><b>&nbsp; &nbsp; key2connection</b> =<span style=""><span style="">&nbsp;</span></span>new ConcurrentHashMap&lt;&gt;();</p><p style="margin: 0px 0px 0px 4px;"><br></p><p style="margin: 0px 0px 0px 4px;">private final SemaphorePubSub semaphorePubSub = new SemaphorePubSub(this);</p><p style="margin: 0px 0px 0px 4px;"><br></p><p style="margin: 0px 0px 0px 4px;">private final CountDownLatchPubSub countDownLatchPubSub = new CountDownLatchPubSub(this);</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//同一个Redisson实例内部只有一个 PublishSubscribeService 也只有一个 LockPubSub实例</font></p><p style="margin: 0px 0px 0px 4px;">private final <b>LockPubSub</b> <b>lockPubSub</b> = new LockPubSub(this);</p><p style="margin: 0px 0px 0px 4px;"><br></p><p style="margin: 0px 0px 0px 4px;">private final Set&lt;PubSubConnectionEntry&gt; trackedEntries = Collections.newSetFromMap(new ConcurrentHashMap&lt;&gt;());</p><p style="margin: 0px 0px 0px 4px;">private boolean shardingSupported = false;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-880" y="1320" width="400" height="480" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-19" value="<div style="font-size: 11px;">结合 JUC 锁实现基本原理对比 Redisson分布式锁实现(<span style="background-color: initial;">下面省略很多细节):</span></div><div style="font-size: 11px;"><br></div><div style="font-size: 11px;"><b>JUC锁</b>:</div><div style="font-size: 11px;">对 volatile int字段执行CAS操作加锁,同时只有一个加锁成功,未加锁成功的到队列中排队,锁释放后从队列头部唤醒等待的线程重新竞争加锁;</div><div style="font-size: 11px;"><br></div><div style="font-size: 11px;"><b>Redisson分布式锁</b>:</div><div style="font-size: 11px;"><span style="background-color: initial;">加锁是借助Hash数据类型通过发送lua脚本执行 hincrby pexpire 实现,同时只有一个线程加锁成功(成功返回nil),未加锁成功的线程先订阅主题&nbsp;&nbsp;redisson_lock__channel:{&lt;lockName&gt;},再尝试获取信号量(RedissonLockEntry.latch,初始为0)只有成功获取信号量的才可以继续尝试获取锁,获取锁的线程执行完同步代码释放锁会发布释放锁的消息进而给latch++, 这样就可以推动其他等待的线程继续尝试获取锁,从而实现线程同步</span><br></div><div style="font-size: 11px;"><br></div><div style=""><div style=""><b>看门狗机制</b>:</div><div style="">成功加锁后,会调用 scheduleExpirationRenewal(threadId) 通过 ServiceManager 中的线程池注册一个用于自动续约的超时任务(一次性任务),延迟 internalLockLeaseTime / 3 ms(默认是10s)后执行,每次执行会向Redis Server 发送Lua脚本修改超时时间,修改完超时时间还会调用自己再注册一个超时任务,这样就可以一直续约下去;解锁时会取消续约。</div></div>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="40" y="240" width="440" height="280" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-24" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.005;exitY=0.287;exitDx=0;exitDy=0;endArrow=open;endFill=0;exitPerimeter=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-20" target="dYNV18oPOYucMmK5HlVg-21" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-20" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>PublishSubscribe&lt;E extends PubSubEntry&lt;E&gt;&gt; (A)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><b><font color="#007fff">发布订阅逻辑封装,包含 PubSubEntry 集合</font></b></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><br></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><font color="#007fff">//这个其实是待注册的订阅节点容器</font></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><font color="#007fff">//entryName (<b>ServiceManagerID:锁名</b>) -&gt; PubSubEntry实现类实例</font></span></p><p style="margin: 0px 0px 0px 4px;">private final ConcurrentMap&lt;String, E&gt; <b>entries</b> = new ConcurrentHashMap&lt;&gt;();</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//所属发布订阅服务</font></p><p style="margin: 0px 0px 0px 4px;">private final PublishSubscribeService <b>service</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">public void unsubscribe(E entry, String entryName, String channelName)<br style="font-size: 11px;"></p><p style="margin: 0px 0px 0px 4px;">public void timeout(CompletableFuture&lt;?&gt; promise)<br></p><p style="margin: 0px 0px 0px 4px;">public void timeout(CompletableFuture&lt;?&gt; promise, long timeout)<br></p><p style="margin: 0px 0px 0px 4px;">public CompletableFuture&lt;E&gt; subscribe(String entryName, String channelName)<br></p><p style="margin: 0px 0px 0px 4px;"><br></p><p style="margin: 0px 0px 0px 4px;">protected abstract E createEntry(CompletableFuture&lt;E&gt; newPromise);</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//用于自定义订阅回调</font></p><p style="margin: 0px 0px 0px 4px;">protected abstract void onMessage(E value, Long message);</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//将子类的onMessage重新封装成RedisPubSubListener注册到连接中的监听器队列</font></p><p style="margin: 0px 0px 0px 4px;">private RedisPubSubListener&lt;Object&gt; createListener(String channelName, E value)<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-1320" y="1440" width="400" height="300" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-21" value="<div style="text-align: center;"><b>PubSubEntry&lt;E&gt; (I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><b>订阅监听节点</b></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><br></font></p><p style="margin: 0px 0px 0px 4px;">void acquire();</p><p style="margin: 0px 0px 0px 4px;">int release();</p><p style="margin: 0px 0px 0px 4px;"></p><p style="margin: 0px 0px 0px 4px;">CompletableFuture&lt;E&gt; getPromise();</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"></font></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-1760" y="1440" width="400" height="120" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-23" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=0;dashed=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-25" target="dYNV18oPOYucMmK5HlVg-21" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="-1540" y="1600" as="sourcePoint" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-25" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>RedissonLockEntry</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><b><font color="#007fff">等待锁的订阅监听节点</font></b></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><br></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><font color="#007fff">//订阅时++, 取消订阅时--</font></span></p><p style="margin: 0px 0px 0px 4px;">private volatile int <b>counter</b>;&nbsp;</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//初始permits == 0 的 JUC 信号量,用于<b>阻塞竞争锁失败的线程</b></font><br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff"><b>//解锁时会执行 latch.release()方法,收到监听回调时也会 release()</b></font></p><p style="margin: 0px 0px 0px 4px;">private final Semaphore <b>latch</b>;&nbsp;</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//注册订阅成功后通过这个字段返回 RedissonLockEntry 实例</font></p><p style="margin: 0px 0px 0px 4px;">private final CompletableFuture&lt;RedissonLockEntry&gt; <b>promise</b>;</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//异步加锁时有注册,监听回调时会调用</font></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">private final ConcurrentLinkedQueue&lt;Runnable&gt; </span><b style="background-color: initial;">listeners</b><span style="background-color: initial;"> = new </span><span style="background-color: initial;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: initial;">ConcurrentLinkedQueue&lt;Runnable&gt;();</span></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">public void addListener(Runnable listener);<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-1760" y="1600" width="400" height="240" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-32" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-26" target="dYNV18oPOYucMmK5HlVg-31" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-33" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-32" vertex="1" connectable="0">
<mxGeometry x="0.8967" y="-4" relative="1" as="geometry">
<mxPoint y="-4" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-54" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-26" target="dYNV18oPOYucMmK5HlVg-53" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-55" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-54" vertex="1" connectable="0">
<mxGeometry x="0.2674" y="-2" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-71" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-26" target="dYNV18oPOYucMmK5HlVg-70" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-72" value="3" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-71" vertex="1" connectable="0">
<mxGeometry x="0.9694" y="2" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-26" value="<div style="font-size: 10px;">long threadId = Thread.currentThread().getId();</div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;"><b style="font-size: 10px;">//1 即异步尝试获取锁</b></font></div><div style="font-size: 10px;">Long ttl = <b style="font-size: 10px;">tryAcquire</b>(-1, leaseTime, unit, threadId);</div><div style="font-size: 10px;"><span style="background-color: initial; font-size: 10px;">if (ttl == null) {<span style="font-size: 10px;"><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><font color="#007fff" style="font-size: 10px;">//后面逻辑可知成功获取到ttl会返回null,失败会返回其他线程锁占用超时时间</font></span><br style="font-size: 10px;"></div><div style="font-size: 10px;">&nbsp; &nbsp; return; <font color="#007fff">//获取锁成功退出</font></div><div style="font-size: 10px;"><font color="#007fff">}</font></div><div style="font-size: 10px;"><br></div><div style="font-size: 10px;"><b style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">//2 即尝试获取锁失败(锁被其他线程占用),通过发布订阅实现“JUC锁获取失败入对等待唤醒”类似的逻辑</font></b></div><div style="font-size: 10px;">CompletableFuture&lt;RedissonLockEntry&gt; future = <b style="font-size: 10px;">subscribe</b>(threadId);</div><div style="font-size: 10px;"><font color="#007fff">//注册一个超时任务当订阅超时还未订阅成功就异常结束,超时前订阅成功则删除此超时任务</font></div><div style="font-size: 10px;"><b>pubSub</b>.<b style="font-size: 10px;">timeout</b>(future);</div><div style="font-size: 10px;">RedissonLockEntry entry;</div><font color="#007fff">//t同步等待CompletableFuture&lt;RedissonLockEntry&gt;完成</font><div style="font-size: 10px;">if (interruptibly) {</div><div style="font-size: 10px;">&nbsp; &nbsp; entry = commandExecutor.<b>getInterrupted</b>(future);</div><div style="font-size: 10px;">} else {</div><div style="font-size: 10px;">&nbsp; <font color="#007fff">&nbsp; <b>//3 同步等待订阅成功</b></font></div><div style="font-size: 10px;">&nbsp; &nbsp; entry = commandExecutor.<b>get</b>(future);</div><div style="font-size: 10px;">}</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;">try {</div><div style="font-size: 10px;">&nbsp; &nbsp; while (true) {</div><div style="font-size: 10px;"><font color="#007fff"><span style="white-space: pre;">	</span>//订阅成功后先再执行一次尝试获取锁,这里绝对参考了JDK源码实现</font></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; ttl = <b style="font-size: 10px;">tryAcquire</b>(-1, leaseTime, unit, threadId);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; // lock acquired</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; if (ttl == null) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;"><span style="background-color: initial;"><font color="#007fff"><span style="white-space: pre;">	</span>//还是获取锁失败</font></span></div><div style="font-size: 10px;"><span style="background-color: initial;">&nbsp; &nbsp; &nbsp; &nbsp; if (ttl &gt;= 0) {<span style="white-space: pre;">	</span><font color="#007fff"><b>//自旋重试</b></font></span><br></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {</div><div style="font-size: 10px;"><b><font color="#007fff"><span style="white-space: pre;">	</span><span style="white-space: pre;">	</span>//4 RedissonLockEntry latch 起作用了,尝试获取JUC信号量,像RedissonLock只有其他线程解锁时这个信号量才会++,这里才会成功获取信号量<br></font></b></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry.getLatch().<b>tryAcquire</b>(ttl, TimeUnit.MILLISECONDS);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (InterruptedException e) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (interruptibly) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw e;</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry.getLatch().<b>tryAcquire</b>(ttl, TimeUnit.MILLISECONDS);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp;<span style="white-space: pre;">	</span>&nbsp; &nbsp; &nbsp;<span style="white-space: pre;">	</span><font color="#007fff"><b>//阻塞(ttl超时还没释放锁,就直接阻塞)</b></font></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (interruptibly) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry.getLatch().<b>acquire</b>();</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry.getLatch().<b>acquireUninterruptibly</b>();</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;">} finally {</div><div style="font-size: 10px;">&nbsp; &nbsp; unsubscribe(entry, threadId);</div><div style="font-size: 10px;">}</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#dae8fc;strokeColor=#6c8ebf;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="1640" y="440" width="440" height="640" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-30" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-28" target="dYNV18oPOYucMmK5HlVg-26" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-28" value="<div>lock(-1, null, false);</div><div><font color="#007fff">-1表示没有设置看门狗超时时间,会使用默认的超时时间30s,超时后会自动续约;</font></div><div><font color="#007fff">不可中断;</font></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="1400" y="440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-35" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-31" target="dYNV18oPOYucMmK5HlVg-34" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-31" value="<div>return <b>get</b>(<b>tryAcquireAsync0</b>(</div><div>waitTime, leaseTime, unit, threadId));</div><div><span style="border-color: var(--border-color);"><font style="" color="#007fff">tryAcquireAsync0 返回的是RFuture, get()是<b>同步等待</b>锁获取成功</font></span><br></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="2120" y="440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-37" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-34" target="dYNV18oPOYucMmK5HlVg-36" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-34" value="return getServiceManager().<b>execute</b>(<br>() -&gt; <b>tryAcquireAsync</b>(waitTime, leaseTime, unit, threadId));<br><font color="#007fff">用的ServiceManager的线程池异步执行</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="2360" y="440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-39" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-36" target="dYNV18oPOYucMmK5HlVg-38" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-48" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-39" vertex="1" connectable="0">
<mxGeometry x="0.33" y="-2" relative="1" as="geometry">
<mxPoint y="-27" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-47" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-36" target="dYNV18oPOYucMmK5HlVg-46" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-49" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-47" vertex="1" connectable="0">
<mxGeometry x="0.9021" y="1" relative="1" as="geometry">
<mxPoint x="-2" y="1" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-51" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-36" target="dYNV18oPOYucMmK5HlVg-50" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-52" value="3" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-51" vertex="1" connectable="0">
<mxGeometry x="0.9259" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-36" value="<div style="font-size: 10px;">RFuture&lt;<b>Long</b>&gt; ttlRemainingFuture;</div><div style="font-size: 10px;">if (leaseTime &gt; 0) {</div><div style="font-size: 10px;"><font color="#007fff"><b>&nbsp; &nbsp; //1 通过 evalWriteSyncedAsync 发送并执行Lua脚本</b></font></div><div style="font-size: 10px;">&nbsp; &nbsp; ttlRemainingFuture = <b>tryLockInnerAsync</b>(waitTime, <b>leaseTime</b>, unit, threadId, RedisCommands.EVAL_LONG);</div><div style="font-size: 10px;">} else {</div><div style="font-size: 10px;"><b>&nbsp; &nbsp; <font color="#007fff">//1</font></b></div><div style="font-size: 10px;">&nbsp; &nbsp; ttlRemainingFuture = <b>tryLockInnerAsync</b>(waitTime, <b>internalLockLeaseTime</b>,</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);</div><div style="font-size: 10px;">}</div><div style="font-size: 10px;"><font color="#007fff"><b>//2</b> 这个方法内部通过 CompletionStage handle() <b>注册了异常处理逻辑</b>,如果上面逻辑执行<b>抛出异常</b></font><span style="color: rgb(0, 127, 255); background-color: initial;"><b>就执行 unlockInnerAsync() 执行解锁操作</b></span></div><div style="font-size: 10px;">CompletionStage&lt;Long&gt; s = <b>handleNoSync</b>(threadId, ttlRemainingFuture);</div><div style="font-size: 10px;">ttlRemainingFuture = new CompletableFutureWrapper&lt;&gt;(s);</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;"><font color="#007fff">//成功获取到锁之后执行</font></div><div style="font-size: 10px;">CompletionStage&lt;Long&gt; f = ttlRemainingFuture.thenApply(ttlRemaining -&gt; {</div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp;&nbsp;</font><span style="background-color: initial;">if (ttlRemaining == null) { <font color="#007fff">//前面逻辑看到加锁成功正常返回null</font></span></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; if (leaseTime &gt; 0) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; internalLockLeaseTime = unit.toMillis(leaseTime);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div style="font-size: 10px;"><b><font color="#007fff"><span style=""><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>&nbsp; &nbsp; &nbsp; &nbsp; //3 未设置 leaseTime&nbsp;</font><font color="#007fff">添加到期自动续约任务</font></b></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <b>scheduleExpirationRenewal</b>(threadId);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; return ttlRemaining;</div><div style="font-size: 10px;">});</div><div style="font-size: 10px;">return new CompletableFutureWrapper&lt;&gt;(f);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="2600" y="300" width="440" height="340" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-41" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-38" target="dYNV18oPOYucMmK5HlVg-42" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="3560" y="365" as="targetPoint" />
<Array as="points">
<mxPoint x="3530" y="370" />
<mxPoint x="3530" y="250" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-38" value="<div style="font-size: 10px;"><div>return <b>evalWriteSyncedAsync</b>(getRawName(), LongCodec.INSTANCE, command,</div><div><font color="#007fff">"if ((redis.call('exists', KEYS[1]) == 0) " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "or (redis.call('hexists', KEYS[1], ARGV[2]) == 1)) then " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hincrby', KEYS[1], ARGV[2], 1); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[1]); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return nil; " +<span style="white-space: pre;">	</span><span style="white-space: pre;">	</span><span style="white-space: pre;">	</span><span style="white-space: pre;">	</span><span style="white-space: pre;">	</span>//加锁成功是<b>返回nil</b></font></div><div><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; "return redis.call('pttl', KEYS[1]);",</font><span style="white-space: pre;">	</span><font color="#007fff">//已经存在锁但是是被其他线程占用,就<b>返回过期时间</b></font></div><div>Collections.singletonList(getRawName()), unit.toMillis(leaseTime), getLockName(threadId));</div><div><font color="#007fff">这里可以看到 RedissonLock 内部是用的 exists hexists hincrby pexpire 命令实现,先判断此名字的</font></div><div><font color="#007fff">锁是否存在,不存在或者存在但是是当前线程占用的,就hincrby(&gt;1即重入),并设置超时时间</font></div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=6;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="3080" y="300" width="440" height="140" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-44" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-42" target="dYNV18oPOYucMmK5HlVg-43" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-42" value="return <b>commandExecutor</b>.<b>syncedEval</b>(key, codec, evalCommandType, script, keys, params);" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="3560" y="220" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-43" value="<div style="font-size: 10px;">NodeSource source = getNodeSource(key);</div><div style="font-size: 10px;">return <b>evalAsync</b>(source, false, codec, evalCommandType, script, keys, false, params);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;" parent="1" vertex="1">
<mxGeometry x="3800" y="220" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-45" value="CommandAsyncService" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="3825" y="190" width="150" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-46" value="<div style=""><div style=""><div style="">return <b>evalWriteSyncedAsync</b>(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,</div><div style=""><font color="#007fff">&nbsp; &nbsp; "local val = redis.call('get', KEYS[3]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if val ~= false then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return tonumber(val);" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff"><br></font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return nil;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (counter &gt; 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[2]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[3], 0, 'px', ARGV[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 0; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "else " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('del', KEYS[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call(ARGV[4], KEYS[2], ARGV[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[3], 1, 'px', ARGV[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 1; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; ",</font></div><div style="">&nbsp; &nbsp; Arrays.asList(getRawName(), getChannelName(), <b>getUnlockLatchName</b>(requestId)), <font color="#007fff">//KEYS</font></div><div style="">&nbsp; &nbsp; LockPubSub.<b>UNLOCK_MESSAGE</b>, <b>internalLockLeaseTime</b>,</div><div style="">&nbsp; &nbsp; <b>getLockName</b>(threadId), getSubscribeService().getPublishCommand(), timeout);<span style="white-space: pre;">	</span><font color="#007fff">//ARGVS</font></div><div style=""><br></div></div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=3;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="3080" y="460" width="440" height="300" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="dYNV18oPOYucMmK5HlVg-50" target="LtS7gfKAsIHDJF8mLO0w-5">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-11" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="LtS7gfKAsIHDJF8mLO0w-10">
<mxGeometry x="-0.1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-50" value="<div style=""><div style="">ExpirationEntry entry = new ExpirationEntry();</div><div style="">ExpirationEntry oldEntry = <b>EXPIRATION_RENEWAL_MAP</b>.<b>putIfAbsent</b>(getEntryName(), entry);</div><div style="">if (<b>oldEntry != null</b>) {</div><div style="">&nbsp; &nbsp; oldEntry.addThreadId(threadId);</div><div style="">} else {</div><div style="">&nbsp; &nbsp; entry.addThreadId(threadId);</div><div style="">&nbsp; &nbsp; try {</div><div style=""><font color="#007fff"><span style=""><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="white-space: pre;">	</span></span></span>//1 内部通过 ServiceManager 注册一个自动续约的超时任务,延迟&nbsp;</font><font color="#007fff">internalLockLeaseTime / 3</font></div><div style=""><font color="#007fff"><span style="white-space: pre;">	</span>ms后执行,每次执行自动续约逻辑会调用自己再注册一个超时任务,这样就可以一直续约下去<br></font></div><div style=""><font color="#007fff"><span style="white-space: pre;">	</span>解锁时会取消续约<br></font></div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; <b>renewExpiration</b>();</div><div style="">&nbsp; &nbsp; } finally {</div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; if (Thread.currentThread().isInterrupted()) {</div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelExpirationRenewal(threadId, null); <font color="#007fff">//线程被中断就取消自动续约任务</font></div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="">&nbsp; &nbsp; }</div><div style="">}</div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=6;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="3080" y="780" width="440" height="220" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-57" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-53" target="dYNV18oPOYucMmK5HlVg-56" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-53" value="<div><div>return pubSub.<b>subscribe</b>(</div><div>getEntryName(), getChannelName());<br></div></div><div style="font-size: 10px;"><font style="font-size: 10px;" color="#007fff">entryName 是 ServiceManager的<b>id:lock-1</b></font></div><div style="font-size: 10px;"><font style="font-size: 10px;" color="#007fff">订阅的主题是 <b>redisson_lock__channel:{lock-1}</b></font><br></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="2120" y="710" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-65" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-56" target="dYNV18oPOYucMmK5HlVg-64" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-66" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-65" vertex="1" connectable="0">
<mxGeometry x="0.8286" y="-3" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-73" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=-0.002;exitY=0.914;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitPerimeter=0;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="dYNV18oPOYucMmK5HlVg-56" target="dYNV18oPOYucMmK5HlVg-70" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-74" value="唤醒" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-73" vertex="1" connectable="0">
<mxGeometry x="-0.5262" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-56" value="<div style=""><div style=""><div style="font-size: 10px;"><font color="#007fff">//获取PublishSubscribeService locks 中的一个锁(令牌数量为1的信号量就是锁)</font></div><div style="font-size: 10px;">AsyncSemaphore <b>semaphore</b> = service.getSemaphore(new ChannelName(channelName));</div><div style="font-size: 10px;"><font color="#007fff">//这里E泛型是&nbsp;RedissonLockEntry,通过这个CompletableFuture 实例将下面创建的 RedissonLockEntry 返回</font></div><div style="font-size: 10px;">CompletableFuture&lt;E&gt; <b>newPromise</b> = new CompletableFuture&lt;&gt;();</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;">semaphore.acquire().thenAccept(c -&gt; {<span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><font color="#007fff">//同步订阅操作</font></div><div style="font-size: 10px;">&nbsp; &nbsp; if (newPromise.isDone()) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; semaphore.release();</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; return;</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; E entry = <b>entries</b>.get(entryName);</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; if (entry != null) {</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; entry.<b>acquire</b>();</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; semaphore.release();</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; entry.getPromise().whenComplete((r, e) -&gt; {</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (e != null) {</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newPromise.completeExceptionally(e);</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newPromise.<b>complete</b>(r);</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; });</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; return;</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; }</font></div><div style="font-size: 10px;"><font color="#3333ff"><br></font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; //创建&nbsp;RedissonLockEntry&nbsp;</font></div><div style="font-size: 10px;">&nbsp; &nbsp; E value = <b>createEntry</b>(newPromise);</div><div style="font-size: 10px;">&nbsp; &nbsp; value.acquire();<span style=""><span style="">&nbsp;&nbsp;&nbsp;<font color="#007fff">&nbsp;</font></span></span><font color="#007fff">//将RedissonLockEntry<span style="background-color: initial;">&nbsp;counter++</span></font></div><div style="font-size: 10px;">&nbsp; &nbsp; E oldValue = <b>entries</b>.<b>putIfAbsent</b>(entryName, value);</div><div style="font-size: 10px;">&nbsp; &nbsp;<font color="#3333ff"> if (oldValue != null) { //加了同步控制不太可能不为null吧</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; oldValue.acquire();</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; semaphore.release();</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; oldValue.getPromise().whenComplete((r, e) -&gt; {</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (e != null) {</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newPromise.completeExceptionally(e);</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newPromise.complete(r);</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; });</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; &nbsp; &nbsp; return;</font></div><div style="font-size: 10px;"><font color="#3333ff">&nbsp; &nbsp; }</font></div><div style=""><b><font style="font-size: 10px;" color="#007fff">&nbsp; &nbsp; //1 创建发布订阅监听器并注册,订阅的主题是</font><font color="#007fff">&nbsp;redisson_lock__channel:{lock-1}</font></b></div><div style="font-size: 10px;">&nbsp; &nbsp; RedisPubSubListener&lt;Object&gt; listener = <b>createListener</b>(<b>channelName</b>, value);</div><div style="font-size: 10px;"><font color="#007fff"><b>&nbsp; &nbsp; //订阅方法逻辑参考发布订阅分析</b></font></div><div style="font-size: 10px;">&nbsp; &nbsp; CompletableFuture&lt;PubSubConnectionEntry&gt; s = <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>service.<b>subscribeNoTimeout</b>(LongCodec.INSTANCE, <b>channelName</b>, semaphore, listener);</div><div style="font-size: 10px;">&nbsp; &nbsp; newPromise.whenComplete((r, e) -&gt; {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; if (e != null) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.completeExceptionally(e);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; });</div><div style="font-size: 10px;">&nbsp; &nbsp; s.whenComplete((r, e) -&gt; {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; if (e != null) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entries.<b>remove</b>(entryName);<font color="#007fff">//订阅成功后从entries中删除,说明entries就是一个待注册的监听器容器</font></div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value.getPromise().completeExceptionally(e);</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; value.getPromise().<b>complete</b>(value); <font color="#007fff">//订阅成功后返回 RedissonLockEntry</font></div><div style="font-size: 10px;">&nbsp; &nbsp; });</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;">});</div><div style="font-size: 10px;"><br style="font-size: 10px;"></div><div style="font-size: 10px;">return <b>newPromise</b>;</div></div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=1;" parent="1" vertex="1">
<mxGeometry x="2360" y="710" width="440" height="770" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-61" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-60" target="dYNV18oPOYucMmK5HlVg-20" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-60" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>LockPubSub </b>extends PublishSubscribe&lt;RedissonLockEntry&gt;<br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><b>用于实现分布式锁的发布订阅逻辑封装</b></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">在 PublishSubscribe 基础上重写了 createEntry() onMessage() 这两个protected方法</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><br></span></p><p style="margin: 0px 0px 0px 4px;">public static final Long UNLOCK_MESSAGE = 0L;</p><p style="margin: 0px 0px 0px 4px;">public static final Long READ_UNLOCK_MESSAGE = 1L;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">//用于自定义订阅回调</p><p style="margin: 0px 0px 0px 4px;">protected abstract void onMessage(E value, Long message);</p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-1320" y="1760" width="400" height="160" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-62" value="LockPubSub" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="2535" y="680" width="90" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-64" value="<div><font color="#3333ff">//这里是左边注册的回调逻辑</font></div><div>protected void <b>onMessage</b>(RedissonLockEntry value, Long message) {</div><div>&nbsp; &nbsp; if (message.equals(<b>UNLOCK_MESSAGE</b>)) { <font color="#3333ff">//解锁消息</font></div><div><font color="#3333ff"><span style=""><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span>//从 RedissonLockEntry listeners 中 poll 一个执行 run()<br></font></div><div>&nbsp; &nbsp; &nbsp; &nbsp; value.<b>tryRunListener</b>();</div><div><b><font color="#007fff"><span style="white-space: pre;">	</span>//RedissonLockEntry latch ++</font><br></b></div><div>&nbsp; &nbsp; &nbsp; &nbsp; value.<b>getLatch().release()</b>;</div><div>&nbsp; &nbsp; } else if (message.equals(<b>READ_UNLOCK_MESSAGE</b>)) { <font color="#3333ff">//解读<span style="background-color: initial;">锁消息</span></font></div><div><font color="#007fff"><span style=""><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span>//遍历 RedissonLockEntry listeners 中所有listener 执行 run()<br></font></div><div>&nbsp; &nbsp; &nbsp; &nbsp; value.<b>tryRunAllListeners</b>();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; value.<b>getLatch().release(value.getLatch().getQueueLength())</b>;</div><div>&nbsp; &nbsp; }</div><div>}<br></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;align=left;fillColor=#fff2cc;strokeColor=#d6b656;arcSize=6;" parent="1" vertex="1">
<mxGeometry x="2840" y="1139" width="440" height="181" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-67" value="LockPubSub" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="3015" y="1109" width="90" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-70" value="<div><div>entry = commandExecutor.get(future);<br></div></div><div style="font-size: 10px;"><font color="#007fff"><b>内部调用 future.get()</b></font></div><div style="font-size: 10px;"><font color="#007fff"><b>阻塞等待CF完成</b></font></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="2120" y="1520" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-80" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-77" target="dYNV18oPOYucMmK5HlVg-79" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-77" value="get(<b>unlockAsync</b>(<br>Thread.currentThread().getId()));<br><font color="#007fff">get() 是同步获取解锁结果</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="1400" y="1600" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-82" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-79" target="dYNV18oPOYucMmK5HlVg-81" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-79" value="return getServiceManager().execute(() -&gt; <b>unlockAsync0</b>(threadId));<br><font color="#007fff">异步解锁</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="1640" y="1600" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-84" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="dYNV18oPOYucMmK5HlVg-81" target="dYNV18oPOYucMmK5HlVg-83" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-88" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-84" vertex="1" connectable="0">
<mxGeometry x="0.6738" y="4" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="dYNV18oPOYucMmK5HlVg-81" target="LtS7gfKAsIHDJF8mLO0w-1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-3" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="LtS7gfKAsIHDJF8mLO0w-2">
<mxGeometry x="0.9143" y="-3" relative="1" as="geometry">
<mxPoint y="-3" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-81" value="<div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">//1 执行Lua脚本和命令释放锁</font></div><div style="font-size: 10px;">CompletionStage&lt;Boolean&gt; future = <b style="font-size: 10px;">unlockInnerAsync</b>(threadId);</div><div style="font-size: 10px;">CompletionStage&lt;Void&gt; f = future.<b style="font-size: 10px;">handle</b>((res, e) -&gt; {</div><div style="font-size: 10px;"><b>&nbsp; &nbsp; <font color="#007fff" style="font-size: 10px;">//2 取消掉自动续约</font></b></div><div style="font-size: 10px;">&nbsp; &nbsp; <b style="font-size: 10px;">cancelExpirationRenewal</b>(threadId, res);&nbsp;</div><div style="font-size: 10px;">&nbsp; &nbsp; ...</div><div style="font-size: 10px;">&nbsp; &nbsp; return null;</div><div style="font-size: 10px;">});</div><div style="font-size: 10px;">return new CompletableFutureWrapper&lt;&gt;(f);</div><font color="#007fff" style="font-size: 10px;">异步解锁</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=4;" parent="1" vertex="1">
<mxGeometry x="1880" y="1600" width="440" height="140" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-83" value="<div style="font-size: 10px;"><div style="font-size: 10px;">String id = getServiceManager().generateId();</div><div style="font-size: 10px;">MasterSlaveServersConfig config = getServiceManager().getConfig();</div><div style="font-size: 10px;">int timeout = (config.getTimeout() + config.getRetryInterval()) * config.getRetryAttempts();</div><div style="font-size: 10px;">timeout = Math.max(timeout, 1);</div><div style="font-size: 10px;"><font color="#007fff">//1 通过Lua脚本 <b>释放锁</b>,并<b>发布解锁消息</b></font></div><div style="font-size: 10px;">RFuture&lt;Boolean&gt; r = <b>unlockInnerAsync</b>(threadId, id, timeout); <font color="#007fff">//返回1解锁成功,0只是降低重入</font></div><div style="font-size: 10px;">CompletionStage&lt;Boolean&gt; ff = r.thenApply(v -&gt; {</div><div style="font-size: 10px;">&nbsp; &nbsp; CommandAsyncExecutor ce = commandExecutor;</div><div style="font-size: 10px;">&nbsp; &nbsp; if (ce instanceof CommandBatchService) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; ce = new CommandBatchService(commandExecutor);</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; //2 异步发送命令 “<b>del&nbsp;redisson_unlock_latch:{lock-1:id}</b>"</font></div><div style="font-size: 10px;">&nbsp; &nbsp; ce.<b>writeAsync</b>(getRawName(), LongCodec.INSTANCE, RedisCommands.DEL, <span style=""><span style="white-space: pre;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="white-space: pre;">	</span></span></span>getUnlockLatchName(id));</div><div style="font-size: 10px;">&nbsp; &nbsp; if (ce instanceof CommandBatchService) {</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; ((CommandBatchService) ce).executeAsync();</div><div style="font-size: 10px;">&nbsp; &nbsp; }</div><div style="font-size: 10px;">&nbsp; &nbsp; return <b>v</b>;</div><div style="font-size: 10px;">});</div><div style="font-size: 10px;">return new CompletableFutureWrapper&lt;&gt;(ff);</div><div style="font-size: 10px;"><br></div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;arcSize=4;" parent="1" vertex="1">
<mxGeometry x="2360" y="1600" width="440" height="260" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-90" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.7;exitDx=0;exitDy=0;fillColor=#dae8fc;strokeColor=#6c8ebf;exitPerimeter=0;" parent="1" source="dYNV18oPOYucMmK5HlVg-46" target="dYNV18oPOYucMmK5HlVg-64" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="3280" y="1802.5" as="sourcePoint" />
<Array as="points">
<mxPoint x="3530" y="670" />
<mxPoint x="3530" y="1162" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-91" value="<font color="#007fff" style="font-size: 10px;">发布解锁消息,<br>解锁消息是Long型的0<br></font>" style="edgeLabel;html=1;align=left;verticalAlign=middle;resizable=0;points=[];" parent="dYNV18oPOYucMmK5HlVg-90" vertex="1" connectable="0">
<mxGeometry x="-0.9479" y="-1" relative="1" as="geometry">
<mxPoint x="1" y="31" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-87" value="RedissonBaseLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="1675" y="1570" width="130" height="30" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-92" value="<font color="#007fff"><br>exists&nbsp; lock-1<br>hexists lock-1 &lt;threadId&gt;<br><b>hincrby&nbsp;lock-1 &lt;threadId&gt; 1</b><br><b>pexpire&nbsp;lock-1 &lt;leaseTime&gt;</b><br><br><br>pttl lock-1</font>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=10;" parent="1" vertex="1">
<mxGeometry x="3540" y="300" width="240" height="140" as="geometry" />
</mxCell>
<mxCell id="dYNV18oPOYucMmK5HlVg-93" value="<font color="#007fff"><b>get &lt;requetId&gt;</b>&nbsp; &nbsp;//requestId 是用ServiceManager 生成的 UUID<br><br><br><br><br><b>hexists lock-1 &lt;threadId&gt;<br></b><br><br><b>hincrby lock-1&nbsp;</b></font><span style="border-color: var(--border-color);"><font style="" color="#007fff"><b>&lt;threadId&gt; -1</b><br>counter &gt; 0 说明是多次重入(只是减少了一次重入计数,并不是真正释放锁)<br></font></span><font color="#007fff"><b>pexpire lock-1 &lt;internalLockLeaseTime&gt;<br>set&nbsp;redisson_unlock_latch:{lock-1:&lt;</b></font><b style="border-color: var(--border-color); color: rgb(0, 127, 255);">requetId</b><font color="#007fff"><b>&gt;} 0 px &lt;timeout&gt;</b><br><br>counter &lt;= 0 解锁成功:<br><b>del&nbsp;</b></font><font color="#007fff"><b>lock-1<br></b></font><font color="#007fff"><b>publish redisson_lock__channel:{lock-1} 0&nbsp;</b> //&nbsp;0是解锁的意思,解锁回调会给 RedissonLockEntry.latch++<br><b>set redisson_unlock_latch:{lock-1:&lt;requetId&gt;} 0 px &lt;timeout&gt;&nbsp;<br></b><br></font>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=10;" parent="1" vertex="1">
<mxGeometry x="3541" y="480" width="539" height="210" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-1" value="<div style="">&nbsp; &nbsp; <b>cancelExpirationRenewal</b>(<br>threadId, res);&nbsp;</div><font color="#007fff">取消自动续约</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
<mxGeometry x="2360" y="1880" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="LtS7gfKAsIHDJF8mLO0w-5" target="LtS7gfKAsIHDJF8mLO0w-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-5" value="Timeout task = getServiceManager().newTimeout(new TimerTask() {<br>&nbsp; &nbsp; ...<br><font color="#007fff">&nbsp; &nbsp; //发送Lua脚本执行续约</font><br>&nbsp; &nbsp;&nbsp;CompletionStage&lt;Boolean&gt; future = <b>renewExpirationAsync</b>(threadId);<br>&nbsp; &nbsp; ...<br><div style=""><span style="background-color: initial;">}</span></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;align=left;" vertex="1" parent="1">
<mxGeometry x="3560" y="850" width="400" height="80" as="geometry" />
</mxCell>
<mxCell id="LtS7gfKAsIHDJF8mLO0w-6" value="<div>return evalWriteSyncedAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<font color="#007fff">"if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[1]); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 1; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return 0;",</font></div><div>&nbsp; &nbsp; Collections.singletonList(getRawName()),</div><div>&nbsp; &nbsp; internalLockLeaseTime, getLockName(threadId));</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;align=left;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
<mxGeometry x="4000" y="820" width="400" height="140" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="eGQscOvwRYNp3SZoV_GP" name="RedissonReadWriteLock">
<mxGraphModel dx="3088" dy="-290" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-1" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-2" target="nCa2Bj8YOzRUgJI6Qu_I-4" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-2" value="RedissonReadWriteLock" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="40" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-4" target="nCa2Bj8YOzRUgJI6Qu_I-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-4" value="RedissonReadWriteLockTest#<br style="font-size: 11px;">testRWLockUnlock()<br style="font-size: 11px;"><font color="#007fff" style="font-size: 11px;">创建两个线程,一个多次读(每次读加读锁),一个先读后写(读时加读锁,写时加写锁)</font>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="280" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-6" target="nCa2Bj8YOzRUgJI6Qu_I-8" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-19" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-6" target="nCa2Bj8YOzRUgJI6Qu_I-18" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-6" value="RReadWriteLock rwLock = redisson.getReadWriteLock("lock-rw");" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="520" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-8" target="nCa2Bj8YOzRUgJI6Qu_I-10" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-8" target="Keo2UcvNxaGDYnBjSey5-4" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-8" value="RLock rLock = rwLock.readLock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="520" y="1360" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-9" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-10" target="nCa2Bj8YOzRUgJI6Qu_I-16" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-7" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-10" target="Keo2UcvNxaGDYnBjSey5-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-10" value="RLock wLock = rwLock.writeLock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="520" y="1440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-11" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-12" target="nCa2Bj8YOzRUgJI6Qu_I-14" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-7" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-12" target="XMJwmoDdZTX_D4IhNOn0-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-12" value="rLock.unlock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="1640" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-13" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-14" target="nCa2Bj8YOzRUgJI6Qu_I-17" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-9" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-14" target="1C8W97YoHMhPApq2HqQs-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-14" value="wLock.lock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="2660" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-15" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-16" target="nCa2Bj8YOzRUgJI6Qu_I-12" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-16" target="XMJwmoDdZTX_D4IhNOn0-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-16" value="rLock.lock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="1540" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-10" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="nCa2Bj8YOzRUgJI6Qu_I-17" target="1C8W97YoHMhPApq2HqQs-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-17" value="wLock.unlock();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="520" y="2760" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="nCa2Bj8YOzRUgJI6Qu_I-18" value="return new <b>RedissonReadWriteLock</b>(<br>commandExecutor, name);" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="760" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=1;" parent="1" source="hoS6UmTI4-DL8qWvyoiX-1" target="CeLp3w2RrOelHFvfpKlE-1" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="-580" y="1540" />
<mxPoint x="-240" y="1540" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=1;dashed=1;" parent="1" source="hoS6UmTI4-DL8qWvyoiX-1" target="CeLp3w2RrOelHFvfpKlE-3" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="hoS6UmTI4-DL8qWvyoiX-1" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>RedissonReadWriteLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><b><font color="#007fff">内部依赖 RedissonReadLock RedissonWriteLock 实现</font></b></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//方法内创建 RedissonReadLock</font></p><p style="margin: 0px 0px 0px 4px;">public RLock readLock()<br style="font-size: 11px;"></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//方法内创建 RedissonWriteLock</font><br></p><p style="margin: 0px 0px 0px 4px;">public RLock writeLock()<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-880" y="1560" width="400" height="120" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;endArrow=block;endFill=1;" parent="1" source="CeLp3w2RrOelHFvfpKlE-1" target="Keo2UcvNxaGDYnBjSey5-1" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-1" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonExpirable (A)&nbsp;</b><b style="background-color: initial;">&nbsp;</b><span style="background-color: initial;">extends RedissonObject implements RExpirable</span></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="color: rgb(0, 127, 255); background-color: initial;">拓展超时方法实现,由于Redisson大部分对象都需要支持超时方法,</span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="color: rgb(0, 127, 255); background-color: initial;">Redisson大部分对象类都继承此类</span></p><div style="font-size: 11px;"><br style="font-size: 11px;"></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-440" y="1400" width="400" height="120" as="geometry" />
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=1;" parent="1" source="CeLp3w2RrOelHFvfpKlE-3" target="CeLp3w2RrOelHFvfpKlE-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-3" value="<div style="text-align: center;"><b>RReadWriteLock</b><b style="background-color: initial;">&nbsp;(I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">RLock readLock();<br></p><p style="margin: 0px 0px 0px 4px;">RLock writeLock();</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-880" y="1440" width="400" height="80" as="geometry" />
</mxCell>
<mxCell id="CeLp3w2RrOelHFvfpKlE-5" value="<div style="text-align: center;"><b>ReadWriteLock</b><b style="background-color: initial;">&nbsp;(I)</b></div><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">Lock readLock();<br></p><p style="margin: 0px 0px 0px 4px;">Lock writeLock();<br></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="-880" y="1320" width="400" height="80" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-1" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonObject (A)</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//命令异步执行器,其实封装了</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final <b>CommandAsyncExecutor</b> <b>commandExecutor</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对象名字</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected String <b>name</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对象使用的编解码器</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final Codec <b>codec</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="-440" y="1200" width="400" height="160" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-4" value="return new <b>RedissonReadLock</b>(<br>commandExecutor, getName());" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="760" y="1360" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-5" value="return new <b>RedissonWriteLock</b>(<br>commandExecutor, getName());" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="760" y="1440" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-5" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="Keo2UcvNxaGDYnBjSey5-8" target="Bzvi4axgJ0h4EuhYmm7J-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-8" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>RedissonReadLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><b><font color="#007fff">依赖 RedissonLock 实现,仅仅重写了加锁解锁以及续约锁命名、订阅主题等的方法</font></b></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">String <b>getChannelName</b>()</span><br></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">protected String <b>getLockName</b>(long threadId)</span><br></p><p style="margin: 0px 0px 0px 4px;">&lt;T&gt; RFuture&lt;T&gt; <b>tryLockInnerAsync</b>(long waitTime, long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand&lt;T&gt; command)&nbsp;</p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">protected RFuture&lt;Boolean&gt; <b>unlockInnerAsync</b>(long threadId, String requestId, int timeout)</span><br></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">protected CompletionStage&lt;Boolean&gt; <b>renewExpirationAsync</b>(long threadId)</span><br></p><p style="margin: 0px 0px 0px 4px;"><span style="background-color: initial;">public RFuture&lt;Boolean&gt; <b>forceUnlockAsync</b>()</span><br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-440" y="2080" width="400" height="200" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="Keo2UcvNxaGDYnBjSey5-9" target="Bzvi4axgJ0h4EuhYmm7J-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Keo2UcvNxaGDYnBjSey5-9" value="<p style="margin: 4px 0px 0px; text-align: center;"><b>RedissonWriteLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;"><font color="#007fff"><b>依赖 RedissonLock 实现,仅仅重写了加锁解锁以及续约锁命名、订阅主题等的方法</b></font><br></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px;">String <b style="">getChannelName</b>()</p><p style="margin: 0px 0px 0px 4px;">protected String <b>getLockName</b>(long threadId)<br>&lt;T&gt; RFuture&lt;T&gt; <b>tryLockInnerAsync</b>(long waitTime, long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand&lt;T&gt; command)&nbsp;<br></p><p style="margin: 0px 0px 0px 4px;">protected RFuture&lt;Boolean&gt; <b>unlockInnerAsync</b>(long threadId, String requestId, int timeout)<br></p><p style="margin: 0px 0px 0px 4px;">protected CompletionStage&lt;Boolean&gt; <b>renewExpirationAsync</b>(long threadId)<br></p><p style="margin: 0px 0px 0px 4px;">public RFuture&lt;Boolean&gt; <b>forceUnlockAsync</b>()<br></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-880" y="2080" width="400" height="200" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-3" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=1;" parent="1" source="Bzvi4axgJ0h4EuhYmm7J-1" target="CeLp3w2RrOelHFvfpKlE-1" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-1" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonBaseLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">锁相关对象的基本抽象类,锁相关的大部分类都继承此抽象类</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">private static final ConcurrentMap&lt;String, ExpirationEntry&gt; <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><b>EXPIRATION_RENEWAL_MAP</b> = new ConcurrentHashMap();</p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//锁超时释放时间ms(看门狗超时时间), 对应配置类中的 lockWatchdogTimeout</font></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//默认30s</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected long <b>internalLockLeaseTime</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//对应的ServiceManager id (是UUID), 可能后面逻辑哪里可能需要获取ServiceManager</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final String <b>id</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//id + ":" + name</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final String <b>entryName</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff">//来自Redisson commandExecutor</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final CommandAsyncExecutor <b>commandExecutor</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">private static final RedisCommand&lt;Integer&gt; <b>HGET</b> = new <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>RedisCommand("HGET", new MapValueDecoder(), new <span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>IntegerReplayConvertor(0));</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
<mxGeometry x="-440" y="1560" width="400" height="280" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;endArrow=block;endFill=1;" parent="1" source="Bzvi4axgJ0h4EuhYmm7J-2" target="Bzvi4axgJ0h4EuhYmm7J-1" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Bzvi4axgJ0h4EuhYmm7J-2" value="<p style="margin: 4px 0px 0px; text-align: center; font-size: 11px;"><b style="font-size: 11px;">RedissonLock</b><br style="font-size: 11px;"></p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><font color="#007fff"><b>基本的可重入锁实现</b></font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//锁超时释放时间ms(看门狗超时时间), 对应配置类中的 lockWatchdogTimeout</font></p><p style="margin: 0px 0px 0px 4px;"><font color="#007fff">//默认30s</font></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected long <b style="background-color: initial;">internalLockLeaseTime</b><span style="background-color: initial;">;</span><br></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><span style="background-color: initial;"><font color="#007fff">//来自PublishSubscribeService lockPubSub</font></span></p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">protected final <b>LockPubSub</b> <b>pubSub</b>;</p><p style="margin: 0px 0px 0px 4px; font-size: 11px;">final CommandAsyncExecutor <b>commandExecutor</b>;</p><hr style="font-size: 11px;"><p style="margin: 0px 0px 0px 4px; font-size: 11px;"><br style="font-size: 11px;"></p>" style="verticalAlign=top;align=left;overflow=fill;fontSize=11;fontFamily=Helvetica;html=1;whiteSpace=wrap;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="-440" y="1880" width="400" height="160" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-1" value="<b>RedissonReadWriteLock</b> 依赖 <b>RedissonReadLock</b>、<b>RedissonWriteLock</b>,<br>而这两个类又依赖 <b>RedissonLock</b>" style="text;html=1;align=left;verticalAlign=top;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="40" y="1200" width="440" height="40" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-11" value="..." style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="XMJwmoDdZTX_D4IhNOn0-2" target="XMJwmoDdZTX_D4IhNOn0-10" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-2" value="lock(-1, null, false);<br><font color="#007fff">实现参考RedissonLock流程图</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="760" y="1540" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-4" value="RedissonLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="810" y="1510" width="100" height="30" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-13" value="..." style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="XMJwmoDdZTX_D4IhNOn0-5" target="XMJwmoDdZTX_D4IhNOn0-12" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-5" value="get(unlockAsync(<br>Thread.currentThread().getId()));<br><font color="#007fff">实现参考RedissonLock流程图</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="760" y="1640" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-6" value="RedissonBaseLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="795" y="1610" width="130" height="30" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-8" value="<b style="font-size: 11px;">读读不互斥,读写互斥、写写互斥怎么实现的?</b><br style="font-size: 11px;">Redisson读写锁实现很简单,基本完全依赖 RedissonLock,仅仅重写了少量方法。<br style="font-size: 11px;">看源码可以发现区别就是在被重写的方法的 Lua 脚本中。<br style="font-size: 11px;">读写锁同样使用 Hash 数据类型实现,KEY是锁名,VALUE是2-3组KV;<br>读锁额外需要 String 数据类型记录线程自己加的哪个重入计数的读锁, 以便解读锁时使用。<br style="font-size: 11px;"><br style="font-size: 11px;">第1组KV记录<b>锁的模式</b>(只有读锁时是read模式、有写锁时是write模式):<br style="font-size: 11px;"><div style="font-size: 11px;"><font color="#007fff">hset lock-rw mode read</font></div><div style="font-size: 11px;"><b>读锁实现:</b></div><div style="font-size: 11px;">读锁之间不互斥,有线程加了读锁,其他线程也可以继续加读锁,只需要增加重入计数</div><div style="font-size: 11px;"><font color="#007fff">hset lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt; &lt;reentantCount&gt;</font></div><div style="font-size: 11px;">但是解读锁时只能解自己加的读锁,就需要额外记录下自己加的哪个重入计数的读锁</div><div style="font-size: 11px;"><font color="#007fff">set {lock-rw}:&lt;ServiceManager ID&gt;:&lt;threadId&gt;:rwlock_timeout:&lt;reentrantCount&gt; 1<br style="font-size: 11px;"></font></div><div style="font-size: 11px;"><b>写锁实现:</b></div><div style="font-size: 11px;">已经存在任意读锁或写锁,且加写锁的线程不是当前线程都不能加写锁</div><div style="font-size: 11px;"><font color="#007fff">hset lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt;:write &lt;reentantCount&gt;<br style="font-size: 11px;"></font></div><div style="font-size: 11px;"><br></div>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=11;" parent="1" vertex="1">
<mxGeometry x="40" y="1360" width="460" height="240" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-2" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="XMJwmoDdZTX_D4IhNOn0-10" target="pH-ef3WtU6VLe0I9tWm4-1" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-10" value="<div>ttlRemainingFuture = <br>tryLockInnerAsync(...<span style="background-color: initial;">);</span></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="1000" y="1540" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="XMJwmoDdZTX_D4IhNOn0-12" target="pH-ef3WtU6VLe0I9tWm4-3" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="XMJwmoDdZTX_D4IhNOn0-12" value="<div>CompletionStage&lt;Boolean&gt; future = unlockInnerAsync(threadId);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="1000" y="1640" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-1" value="..." style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="1C8W97YoHMhPApq2HqQs-2" target="1C8W97YoHMhPApq2HqQs-7" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-2" value="lock(-1, null, false);<br><font color="#007fff">实现参考RedissonLock流程图</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="760" y="2660" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-3" value="RedissonLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="810" y="1710" width="100" height="30" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-4" value="..." style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="1C8W97YoHMhPApq2HqQs-5" target="1C8W97YoHMhPApq2HqQs-8" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-5" value="get(unlockAsync(<br>Thread.currentThread().getId()));<br><font color="#007fff">实现参考RedissonLock流程图</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
<mxGeometry x="760" y="2760" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-6" value="RedissonBaseLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" parent="1" vertex="1">
<mxGeometry x="795" y="2730" width="130" height="30" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="1C8W97YoHMhPApq2HqQs-7" target="pH-ef3WtU6VLe0I9tWm4-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-7" value="<div>ttlRemainingFuture = <br>tryLockInnerAsync(...<span style="background-color: initial;">);</span></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="1000" y="2660" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-8" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="1C8W97YoHMhPApq2HqQs-8" target="pH-ef3WtU6VLe0I9tWm4-7" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1C8W97YoHMhPApq2HqQs-8" value="<div>CompletionStage&lt;Boolean&gt; future = unlockInnerAsync(threadId);</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=12;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
<mxGeometry x="1000" y="2760" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-1" value="<div style="font-size: 10px;">return commandExecutor.syncedEval(getRawName(), LongCodec.INSTANCE, command,</div><div style="font-size: 10px;">&nbsp; &nbsp; &nbsp;<font color="#007fff"> &nbsp; "local mode = redis.call('hget', KEYS[1], 'mode'); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (mode == false) then " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hset', KEYS[1], 'mode', 'read'); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hset', KEYS[1], ARGV[2], 1); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[2] .. ':1', 1); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[2] .. ':1', ARGV[1]); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[1]); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return nil; " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (mode == 'read') or (mode == 'write' and redis.call('hexists', KEYS[1], ARGV[3]) == 1) then " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local ind = redis.call('hincrby', KEYS[1], ARGV[2], 1); " +&nbsp;</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local key = KEYS[2] .. ':' .. ind;" +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', key, 1); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', key, ARGV[1]); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local remainTime = redis.call('pttl', KEYS[1]); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], math.max(remainTime, ARGV[1])); " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return nil; " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end;" +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return redis.call('pttl', KEYS[1]);",</font></div><div style="font-size: 10px;">&nbsp; &nbsp; Arrays.&lt;Object&gt;asList(<b>getRawName</b>(), <b>getReadWriteTimeoutNamePrefix</b>(threadId)), <font color="#007fff">//KEYS</font></div><div style="font-size: 10px;">&nbsp; &nbsp; unit.toMillis(<b>leaseTime</b>), <b>getLockName</b>(threadId), <b>getWriteLockName</b>(threadId)); <font color="#007fff">//ARGVS</font></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#fff2cc;strokeColor=#d6b656;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="1241" y="1280" width="479" height="320" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-3" value="<div style=""><div style="">String timeoutPrefix = getReadWriteTimeoutNamePrefix(threadId);</div><div style="">String keyPrefix = getKeyPrefix(threadId, timeoutPrefix);</div><div style=""><br></div><div style="">return evalWriteSyncedAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,</div><div style="">&nbsp; &nbsp; <font color="#007fff">"local val = redis.call('get', KEYS[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "if val ~= false then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return tonumber(val);" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff"><br></font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "local mode = redis.call('hget', KEYS[1], 'mode'); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "if (mode == false) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call(ARGV[3], KEYS[2], ARGV[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[5], 1, 'px', ARGV[4]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return 1; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "local lockExists = redis.call('hexists', KEYS[1], ARGV[2]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "if (lockExists == 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return nil;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "local counter = redis.call('hincrby', KEYS[1], ARGV[2], -1); " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "if (counter == 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hdel', KEYS[1], ARGV[2]); " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "end;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "redis.call('del', KEYS[3] .. ':' .. (counter+1)); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp;&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "if (redis.call('hlen', KEYS[1]) &gt; 1) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "local maxRemainTime = -3; " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "local keys = redis.call('hkeys', KEYS[1]); " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "for n, key in ipairs(keys) do " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "counter = tonumber(redis.call('hget', KEYS[1], key)); " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "if type(counter) == 'number' then " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "for i=counter, 1, -1 do " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local remainTime = redis.call('pttl', KEYS[4] .. ':' .. key .. ':rwlock_timeout:' .. i); " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "maxRemainTime = math.max(remainTime, maxRemainTime);" +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end; " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end; " +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if maxRemainTime &gt; 0 then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], maxRemainTime); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[5], 0, 'px', ARGV[4]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 0; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end;" +&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if mode == 'write' then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[5], 0, 'px', ARGV[4]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 0;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "redis.call('del', KEYS[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "redis.call(ARGV[3], KEYS[2], ARGV[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "redis.call('set', KEYS[5], 1, 'px', ARGV[4]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; "return 1; ",</font></div><div style="">&nbsp; &nbsp; Arrays.&lt;Object&gt;asList(getRawName(), getChannelName(), timeoutPrefix, keyPrefix, getUnlockLatchName(requestId)),</div><div style="">&nbsp; &nbsp; LockPubSub.UNLOCK_MESSAGE, getLockName(threadId), getSubscribeService().getPublishCommand(), timeout);</div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#fff2cc;strokeColor=#d6b656;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="1241" y="1640" width="479" height="760" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-5" value="<div style="font-size: 10px;"><div>return commandExecutor.syncedEval(getRawName(), LongCodec.INSTANCE, command,</div><div>&nbsp; &nbsp; <font color="#007fff">"local mode = redis.call('hget', KEYS[1], 'mode'); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; "if (mode == false) then " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hset', KEYS[1], 'mode', 'write'); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hset', KEYS[1], ARGV[2], 1); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[1]); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "return nil; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; "end; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; "if (mode == 'write') then " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hincrby', KEYS[1], ARGV[2], 1); " +&nbsp;</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local currentExpire = redis.call('pttl', KEYS[1]); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], currentExpire + ARGV[1]); " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return nil; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div><font color="#007fff">&nbsp; &nbsp; "end;" +</font></div><div><font color="#007fff">&nbsp; &nbsp; "return redis.call('pttl', KEYS[1]);",</font></div><div>&nbsp; &nbsp; Arrays.&lt;Object&gt;asList(getRawName()),</div><div>&nbsp; &nbsp; unit.toMillis(leaseTime), getLockName(threadId));</div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#fff2cc;strokeColor=#d6b656;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="1241" y="2440" width="479" height="320" as="geometry" />
</mxCell>
<mxCell id="pH-ef3WtU6VLe0I9tWm4-7" value="<div style=""><div style="">return evalWriteSyncedAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,</div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; <font color="#007fff">"local val = redis.call('get', KEYS[3]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if val ~= false then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return tonumber(val);" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff"><br></font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "local mode = redis.call('hget', KEYS[1], 'mode'); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (mode == false) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call(ARGV[4], KEYS[2], ARGV[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[3], 1, 'px', ARGV[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 1; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "if (mode == 'write') then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local lockExists = redis.call('hexists', KEYS[1], ARGV[3]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "if (lockExists == 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return nil;" +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "else " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "if (counter &gt; 0) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[2]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[3], 0, 'px', ARGV[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 0; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "else " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hdel', KEYS[1], ARGV[3]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "if (redis.call('hlen', KEYS[1]) == 1) then " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('del', KEYS[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call(ARGV[4], KEYS[2], ARGV[1]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "else " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // has unlocked read-locks</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hset', KEYS[1], 'mode', 'read'); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "redis.call('set', KEYS[3], 1, 'px', ARGV[5]); " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "return 1; "+</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end; " +</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; "end; "</font></div><div style=""><font color="#007fff">&nbsp; &nbsp; &nbsp; &nbsp; + "return nil;",</font></div><div style="">&nbsp; &nbsp; Arrays.&lt;Object&gt;asList(getRawName(), getChannelName(), getUnlockLatchName(requestId)),</div><div style="">&nbsp; &nbsp; LockPubSub.READ_UNLOCK_MESSAGE, internalLockLeaseTime, getLockName(threadId), getSubscribeService().getPublishCommand(), timeout);</div></div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#fff2cc;strokeColor=#d6b656;align=left;arcSize=2;" parent="1" vertex="1">
<mxGeometry x="1241" y="2800" width="479" height="560" as="geometry" />
</mxCell>
<mxCell id="0Ggkvq602cG6rRDYgfUz-1" value="<font color="#007fff">hget lock-rw mode<br>//没有加锁<br><b>hset lock-rw mode read<br>hset lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt; 1</b><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;<span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span>//设置锁占用线程以及重入次数<br><b>set {lock-rw}:&lt;ServiceManager ID&gt;:&lt;threadId&gt;:rwlock_timeout:1 1</b><span style="font-weight: bold;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>//?<br>pexpire {lock-rw}:&lt;ServiceManager ID&gt;:&lt;threadId&gt;:rwlock_timeout:1 &lt;leaseTime&gt;<br>pexpire lock-rw &lt;leaseTime&gt;<br>&nbsp;<br><br>//已经加锁,(读锁) 或者 (写锁且 hexists lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt;:write 为true,即当前线程已占用写锁)<br>hincrby lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt; 1<span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><br><br>set&nbsp;&nbsp;{lock-rw}:&lt;ServiceManager ID&gt;:&lt;threadId&gt;:rwlock_timeout:&lt;ind&gt; 1<br>pexpire {lock-rw}:&lt;ServiceManager ID&gt;:&lt;threadId&gt;:rwlock_timeout:&lt;ind&gt; &lt;leaseTime&gt;<br>pttl lock-rw<br>pexpire lock-rw &lt;math.max(remainTime,leaseTime)&gt;<br><div>//已经加锁,但不是读锁且写锁也不是被当前线程占用的<br><span style="background-color: initial;">pttl lock-rw</span></div></font>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=10;" parent="1" vertex="1">
<mxGeometry x="1740" y="1320" width="620" height="220" as="geometry" />
</mxCell>
<mxCell id="0Ggkvq602cG6rRDYgfUz-2" value="<font color="#007fff">hget lock-rw mode<br>//没有加锁<br><b>hset lock-rw mode write<br>hset lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt;:write 1</b><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;<span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span>//设置锁占用线程以及重入次数<br><b>pexpire lock-rw &lt;leaseTime&gt;<br></b><br><br>//已经加锁,写锁且 hexists lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt;:write 为true,即当前线程已占用写锁<br><b>hincrby lock-rw &lt;ServiceManager ID&gt;:&lt;threadId&gt;:write 1<span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><br></b>pttl lock-rw<br><b>pexpire lock-rw &lt;math.max(remainTime,leaseTime)&gt;<br></b><br>//已经加锁但是不是当前线程占用的锁<br>pttl lock-rw<br></font>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=10;" parent="1" vertex="1">
<mxGeometry x="1740" y="2500" width="620" height="220" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="0omL4qdwJT3E1ZYZ94oM" name="RedissonFencedLock">
<mxGraphModel dx="1434" dy="-290" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="GXVI5HAIazDNPrltJS_A-1" value="<b>RedissonFencedLock&nbsp;也依赖&nbsp;RedissonLock 实现,主要流程和 RedissonLock 相同。</b><br>这里只关注拓展以及重写的部分。" style="text;html=1;align=left;verticalAlign=top;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="40" y="1200" width="500" height="40" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-1" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-2" target="v25ogsEL4n66i7TNQ_CB-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-2" value="RedissonFencedLock" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="40" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-4" target="v25ogsEL4n66i7TNQ_CB-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-4" value="RedissonFencedLockTest#<br style="font-size: 11px;">testLockUnlock()<br style="font-size: 11px;"><font color="#007fff" style="font-size: 11px;">创建一个包含100固定线程的线程池,提交10W个FencedLock同步的任务</font>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="280" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-7" target="v25ogsEL4n66i7TNQ_CB-10">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-6" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-7" target="v25ogsEL4n66i7TNQ_CB-19">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-7" value="RFencedLock lock = redisson.<b style="font-size: 11px;">getFencedLock</b>("lock");" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="520" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-8" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="ZQmk_gCC5b-BUXqnwlUP-5" target="v25ogsEL4n66i7TNQ_CB-13">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-9" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-10" target="v25ogsEL4n66i7TNQ_CB-20">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-10" value="Long token = lock.<b>lockAndGetToken</b>(1000, TimeUnit.MILLISECONDS);" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="520" y="1380" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-12" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-13" target="v25ogsEL4n66i7TNQ_CB-21">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-13" value="finally:<br>lock.<b style="font-size: 11px;">unlock</b>();" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="520" y="1600" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-19" value="return new <b style="font-size: 11px;">RedissonFencedLock</b>(<br style="font-size: 11px;">commandExecutor, name);" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="760" y="1280" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="KQztjSwfIuCf9p3Tmu93-2" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-20" target="KQztjSwfIuCf9p3Tmu93-1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="KQztjSwfIuCf9p3Tmu93-3" value="..." style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="KQztjSwfIuCf9p3Tmu93-2">
<mxGeometry x="-0.05" y="-1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-20" value="return get(lockAndGetTokenAsync());<br style="font-size: 11px;"><font color="#007fff" style="font-size: 11px;">加锁逻辑和 RedissonLock 差别不大,仅仅是多返回了一个Token<br>(详细流程参考RedissonLock)<br></font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="760" y="1380" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-21" value="get(unlockAsync(<br>Thread.currentThread().getId()));<br><font color="#007fff">后面和RedissonLock一样</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=11;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="760" y="1600" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="v25ogsEL4n66i7TNQ_CB-26" value="<b>和 RedissonLock 对比:<br></b>RedissonLock 加锁成功没有返回值,RedissonFencedLock 有返回栅栏令牌(fencing token)。<br>RedissonFencedLock 加锁只是比 RedissonLock 多了一句 "<b>incr redisson_lock_token:{&lt;lockName&gt;}</b>“<br>" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="40" y="1360" width="460" height="120" as="geometry" />
</mxCell>
<mxCell id="a66co6WNFgm25bbfFoId-1" value="RedissonFencedLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="795" y="1350" width="130" height="30" as="geometry" />
</mxCell>
<mxCell id="KQztjSwfIuCf9p3Tmu93-1" value="<div style="font-size: 10px;">return commandExecutor.syncedEval(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG_LIST,</div><div style="font-size: 10px;">&nbsp; &nbsp; <font color="#007fff" style="font-size: 10px;">"if (redis.call('exists', KEYS[1]) == 0 " +</font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "or (redis.call('hexists', KEYS[1], ARGV[2]) == 1)) then " +</font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;"><b style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; "local token = redis.call('incr', KEYS[2]);" +&nbsp; //和RedissonLock对比Lua脚本只是多了这一句</b></font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('hincrby', KEYS[1], ARGV[2], 1); " +</font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; "redis.call('pexpire', KEYS[1], ARGV[1]); " +</font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; "return {-1, token}; " +</font></div><div style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">&nbsp; &nbsp; "end; " +</font></div><div style="font-size: 10px;"><font color="#007fff">&nbsp; &nbsp; "return {redis.call('pttl', KEYS[1]), -1};",&nbsp;<span style="white-space: pre;">	</span>//加锁失败</font></div><div style="font-size: 10px;">&nbsp; &nbsp; Arrays.asList(getRawName(), tokenName),</div><div style="font-size: 10px;">&nbsp; &nbsp; unit.toMillis(leaseTime), getLockName(threadId));</div>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;align=left;fillColor=#fff2cc;strokeColor=#d6b656;arcSize=7;" vertex="1" parent="1">
<mxGeometry x="1000" y="1330" width="440" height="160" as="geometry" />
</mxCell>
<mxCell id="ZQmk_gCC5b-BUXqnwlUP-2" value="RedissonBaseLock" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="800" y="1570" width="120" height="30" as="geometry" />
</mxCell>
<mxCell id="ZQmk_gCC5b-BUXqnwlUP-6" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=11;" edge="1" parent="1" source="v25ogsEL4n66i7TNQ_CB-10" target="ZQmk_gCC5b-BUXqnwlUP-5">
<mxGeometry relative="1" as="geometry">
<mxPoint x="620" y="1440" as="sourcePoint" />
<mxPoint x="620" y="1590" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="ZQmk_gCC5b-BUXqnwlUP-5" value="<div style="font-size: 10px;"></div><div style="font-size: 10px;">Long currentToken = lock.getToken();</div><div style="font-size: 10px;">if (Objects.equals(currentToken, token)) {</div><div style="font-size: 10px;">&nbsp; &nbsp; count++;</div>}<br style="font-size: 10px;"><font color="#007fff" style="font-size: 10px;">执行需要同步的逻辑前,重新获取当前token,和旧值比较是否相同,不相同说明锁已经过期</font>" style="rounded=1;whiteSpace=wrap;html=1;fontSize=10;fillColor=#dae8fc;strokeColor=#6c8ebf;align=left;arcSize=7;" vertex="1" parent="1">
<mxGeometry x="520" y="1480" width="200" height="100" as="geometry" />
</mxCell>
<mxCell id="ZQmk_gCC5b-BUXqnwlUP-7" value="<font color="#007fff"><b>incr redisson_lock_token:{flock}</b></font>" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="1444" y="1370" width="210" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>