@@ -288,17 +288,11 @@ public <S, T> MultiNodeResult<T> executeMultiKeyCommand(MultiKeyClusterCommandCa
288
288
int index = 0 ;
289
289
for (byte [] key : keys ) {
290
290
for (RedisClusterNode node : getClusterTopology ().getKeyServingNodes (key )) {
291
-
292
- if (nodeKeyMap .containsKey (node )) {
293
- nodeKeyMap .get (node ).append (PositionalKey .of (key , index ++));
294
- } else {
295
- nodeKeyMap .put (node , PositionalKeys .of (PositionalKey .of (key , index ++)));
296
- }
291
+ nodeKeyMap .computeIfAbsent (node , val -> PositionalKeys .empty ()).append (PositionalKey .of (key , index ++));
297
292
}
298
293
}
299
294
300
295
Map <NodeExecution , Future <NodeResult <T >>> futures = new LinkedHashMap <>();
301
-
302
296
for (Entry <RedisClusterNode , PositionalKeys > entry : nodeKeyMap .entrySet ()) {
303
297
304
298
if (entry .getKey ().isMaster ()) {
@@ -604,7 +598,7 @@ private List<T> toList(Collection<NodeResult<T>> source) {
604
598
*/
605
599
private static class ResultByReferenceKeyPositionComparator implements Comparator <NodeResult <?>> {
606
600
607
- List <ByteArrayWrapper > reference ;
601
+ private final List <ByteArrayWrapper > reference ;
608
602
609
603
ResultByReferenceKeyPositionComparator (byte []... keys ) {
610
604
reference = new ArrayList <>(new ByteArraySet (Arrays .asList (keys )));
@@ -620,11 +614,12 @@ public int compare(NodeResult<?> o1, NodeResult<?> o2) {
620
614
* {@link Comparator} for sorting {@link PositionalKey} by external {@link PositionalKeys}.
621
615
*
622
616
* @author Mark Paluch
617
+ * @author Christoph Strobl
623
618
* @since 2.0.3
624
619
*/
625
620
private static class ResultByKeyPositionComparator implements Comparator <PositionalKey > {
626
621
627
- PositionalKeys reference ;
622
+ private final PositionalKeys reference ;
628
623
629
624
ResultByKeyPositionComparator (byte []... keys ) {
630
625
reference = PositionalKeys .of (keys );
@@ -641,24 +636,25 @@ public int compare(PositionalKey o1, PositionalKey o2) {
641
636
* Value object representing a Redis key at a particular command position.
642
637
*
643
638
* @author Mark Paluch
639
+ * @author Christoph Strobl
644
640
* @since 2.0.3
645
641
*/
646
642
@ Getter
647
643
@ EqualsAndHashCode
648
644
@ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
649
- static class PositionalKey {
645
+ private static class PositionalKey {
650
646
651
647
private final ByteArrayWrapper key ;
652
648
private final int position ;
653
649
654
- public static PositionalKey of (byte [] key , int index ) {
650
+ static PositionalKey of (byte [] key , int index ) {
655
651
return new PositionalKey (new ByteArrayWrapper (key ), index );
656
652
}
657
653
658
654
/**
659
655
* @return binary key.
660
656
*/
661
- public byte [] getBytes () {
657
+ byte [] getBytes () {
662
658
return key .getArray ();
663
659
}
664
660
}
@@ -667,24 +663,25 @@ public byte[] getBytes() {
667
663
* Mutable data structure to represent multiple {@link PositionalKey}s.
668
664
*
669
665
* @author Mark Paluch
666
+ * @author Christoph Strobl
670
667
* @since 2.0.3
671
668
*/
672
669
@ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
673
- static class PositionalKeys implements Iterable <PositionalKey > {
670
+ private static class PositionalKeys implements Iterable <PositionalKey > {
674
671
675
672
private final List <PositionalKey > keys ;
676
673
677
674
/**
678
675
* Create an empty {@link PositionalKeys}.
679
676
*/
680
- public static PositionalKeys empty () {
677
+ static PositionalKeys empty () {
681
678
return new PositionalKeys (new ArrayList <>());
682
679
}
683
680
684
681
/**
685
682
* Create an {@link PositionalKeys} from {@code keys}.
686
683
*/
687
- public static PositionalKeys of (byte []... keys ) {
684
+ static PositionalKeys of (byte []... keys ) {
688
685
689
686
List <PositionalKey > result = new ArrayList <>(keys .length );
690
687
@@ -698,7 +695,7 @@ public static PositionalKeys of(byte[]... keys) {
698
695
/**
699
696
* Create an {@link PositionalKeys} from {@link PositionalKey}s.
700
697
*/
701
- public static PositionalKeys of (PositionalKey ... keys ) {
698
+ static PositionalKeys of (PositionalKey ... keys ) {
702
699
703
700
PositionalKeys result = PositionalKeys .empty ();
704
701
result .append (keys );
@@ -709,14 +706,14 @@ public static PositionalKeys of(PositionalKey... keys) {
709
706
/**
710
707
* Append {@link PositionalKey}s to this object.
711
708
*/
712
- public void append (PositionalKey ... keys ) {
709
+ void append (PositionalKey ... keys ) {
713
710
this .keys .addAll (Arrays .asList (keys ));
714
711
}
715
712
716
713
/**
717
714
* @return index of the {@link PositionalKey}.
718
715
*/
719
- public int indexOf (PositionalKey key ) {
716
+ int indexOf (PositionalKey key ) {
720
717
return keys .indexOf (key );
721
718
}
722
719
0 commit comments