|
48 | 48 | import org.springframework.data.redis.core.ScanOptions;
|
49 | 49 | import org.springframework.lang.Nullable;
|
50 | 50 | import org.springframework.util.Assert;
|
51 |
| -import org.springframework.util.CollectionUtils; |
52 | 51 | import org.springframework.util.ObjectUtils;
|
53 | 52 |
|
54 | 53 | /**
|
@@ -431,23 +430,19 @@ public Long sort(byte[] key, SortParameters params, byte[] storeKey) {
|
431 | 430 |
|
432 | 431 | Assert.notNull(key, "Key must not be null");
|
433 | 432 |
|
434 |
| - List<byte[]> sorted = sort(key, params); |
435 |
| - if (!CollectionUtils.isEmpty(sorted)) { |
436 |
| - |
437 |
| - byte[][] arr = new byte[sorted.size()][]; |
438 |
| - switch (type(key)) { |
439 |
| - |
440 |
| - case SET: |
441 |
| - connection.setCommands().sAdd(storeKey, sorted.toArray(arr)); |
442 |
| - return 1L; |
443 |
| - case LIST: |
444 |
| - connection.listCommands().lPush(storeKey, sorted.toArray(arr)); |
445 |
| - return 1L; |
446 |
| - default: |
447 |
| - throw new IllegalArgumentException("sort and store is only supported for SET and LIST"); |
| 433 | + if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) { |
| 434 | + try { |
| 435 | + return connection.getCluster().sort(key, JedisConverters.toSortingParams(params), storeKey); |
| 436 | + } catch (Exception ex) { |
| 437 | + throw convertJedisAccessException(ex); |
448 | 438 | }
|
449 | 439 | }
|
450 |
| - return 0L; |
| 440 | + |
| 441 | + List<byte[]> sorted = sort(key, params); |
| 442 | + byte[][] arr = new byte[sorted.size()][]; |
| 443 | + connection.keyCommands().unlink(storeKey); |
| 444 | + connection.listCommands().lPush(storeKey, sorted.toArray(arr)); |
| 445 | + return (long) sorted.size(); |
451 | 446 | }
|
452 | 447 |
|
453 | 448 | @Nullable
|
|
0 commit comments