|
15 | 15 | */
|
16 | 16 | package org.springframework.data.redis.connection.lettuce;
|
17 | 17 |
|
18 |
| -import io.lettuce.core.*; |
19 |
| -import io.lettuce.core.cluster.models.partitions.Partitions; |
20 |
| -import io.lettuce.core.cluster.models.partitions.RedisClusterNode.NodeFlag; |
21 |
| - |
22 | 18 | import java.nio.ByteBuffer;
|
23 | 19 | import java.nio.charset.StandardCharsets;
|
24 |
| -import java.util.*; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Collection; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.Date; |
| 25 | +import java.util.Iterator; |
| 26 | +import java.util.LinkedHashMap; |
| 27 | +import java.util.LinkedHashSet; |
| 28 | +import java.util.List; |
| 29 | +import java.util.Map; |
| 30 | +import java.util.Optional; |
| 31 | +import java.util.Set; |
25 | 32 | import java.util.concurrent.TimeUnit;
|
26 | 33 | import java.util.stream.Collectors;
|
27 | 34 |
|
| 35 | +import io.lettuce.core.BitFieldArgs; |
| 36 | +import io.lettuce.core.GeoArgs; |
| 37 | +import io.lettuce.core.GeoCoordinates; |
| 38 | +import io.lettuce.core.GeoWithin; |
| 39 | +import io.lettuce.core.GetExArgs; |
| 40 | +import io.lettuce.core.KeyScanArgs; |
| 41 | +import io.lettuce.core.KeyValue; |
| 42 | +import io.lettuce.core.LMoveArgs; |
| 43 | +import io.lettuce.core.Limit; |
| 44 | +import io.lettuce.core.Range; |
| 45 | +import io.lettuce.core.RedisURI; |
| 46 | +import io.lettuce.core.ScanArgs; |
| 47 | +import io.lettuce.core.ScoredValue; |
| 48 | +import io.lettuce.core.ScriptOutputType; |
| 49 | +import io.lettuce.core.SetArgs; |
| 50 | +import io.lettuce.core.SortArgs; |
| 51 | +import io.lettuce.core.TransactionResult; |
| 52 | +import io.lettuce.core.cluster.models.partitions.Partitions; |
| 53 | +import io.lettuce.core.cluster.models.partitions.RedisClusterNode.NodeFlag; |
| 54 | + |
28 | 55 | import org.springframework.core.convert.converter.Converter;
|
29 | 56 | import org.springframework.dao.DataAccessException;
|
30 | 57 | import org.springframework.data.geo.Distance;
|
|
44 | 71 | import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
45 | 72 | import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
46 | 73 | import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
| 74 | +import org.springframework.data.redis.connection.RedisConfiguration; |
47 | 75 | import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
48 | 76 | import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
49 | 77 | import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
|
54 | 82 | import org.springframework.data.redis.connection.RedisPassword;
|
55 | 83 | import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
56 | 84 | import org.springframework.data.redis.connection.RedisServer;
|
| 85 | +import org.springframework.data.redis.connection.RedisSocketConfiguration; |
| 86 | +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; |
57 | 87 | import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
58 | 88 | import org.springframework.data.redis.connection.RedisZSetCommands;
|
59 | 89 | import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
|
|
85 | 115 | * @author Mark Paluch
|
86 | 116 | * @author Ninad Divadkar
|
87 | 117 | * @author dengliming
|
| 118 | + * @author Chris Bono |
88 | 119 | */
|
89 | 120 | public abstract class LettuceConverters extends Converters {
|
90 | 121 |
|
@@ -535,6 +566,86 @@ public static RedisURI sentinelConfigurationToRedisURI(RedisSentinelConfiguratio
|
535 | 566 | return builder.build();
|
536 | 567 | }
|
537 | 568 |
|
| 569 | + /** |
| 570 | + * Converts a {@link RedisURI} to its corresponding {@link RedisSentinelConfiguration}. |
| 571 | + * |
| 572 | + * @param redisURI the uri containing the Redis Sentinel connection info |
| 573 | + * @return a {@link RedisSentinelConfiguration} representing the Redis Sentinel information in the Redis URI. |
| 574 | + * @since 2.6 |
| 575 | + */ |
| 576 | + public static RedisSentinelConfiguration redisUriToSentinelConfiguration(RedisURI redisURI) { |
| 577 | + |
| 578 | + Assert.notNull(redisURI, "RedisURI is required"); |
| 579 | + Assert.hasText(redisURI.getSentinelMasterId(), "RedisURI must have sentinelMasterId param set"); |
| 580 | + |
| 581 | + RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration(); |
| 582 | + sentinelConfiguration.setMaster(redisURI.getSentinelMasterId()); |
| 583 | + sentinelConfiguration.setDatabase(redisURI.getDatabase()); |
| 584 | + |
| 585 | + for (RedisURI sentinelNodeRedisUri : redisURI.getSentinels()) { |
| 586 | + RedisNode sentinelNode = new RedisNode(sentinelNodeRedisUri.getHost(), sentinelNodeRedisUri.getPort()); |
| 587 | + if (sentinelNodeRedisUri.getPassword() != null) { |
| 588 | + sentinelConfiguration.setSentinelPassword(sentinelNodeRedisUri.getPassword()); |
| 589 | + } |
| 590 | + sentinelConfiguration.addSentinel(sentinelNode); |
| 591 | + } |
| 592 | + |
| 593 | + applyAuthentication(redisURI, sentinelConfiguration); |
| 594 | + |
| 595 | + return sentinelConfiguration; |
| 596 | + } |
| 597 | + |
| 598 | + /** |
| 599 | + * Converts a {@link RedisURI} to its corresponding {@link RedisSocketConfiguration}. |
| 600 | + * |
| 601 | + * @param redisURI the uri containing the Redis connection info using a local unix domain socket |
| 602 | + * @return a {@link RedisSocketConfiguration} representing the connection information in the Redis URI. |
| 603 | + * @since 2.6 |
| 604 | + */ |
| 605 | + public static RedisSocketConfiguration redisUriToSocketConfiguration(RedisURI redisURI) { |
| 606 | + |
| 607 | + Assert.notNull(redisURI, "RedisURI is required"); |
| 608 | + Assert.hasText(redisURI.getSocket(), "RedisURI must have socket path set"); |
| 609 | + |
| 610 | + RedisSocketConfiguration socketConfiguration = new RedisSocketConfiguration(); |
| 611 | + socketConfiguration.setSocket(redisURI.getSocket()); |
| 612 | + socketConfiguration.setDatabase(redisURI.getDatabase()); |
| 613 | + |
| 614 | + applyAuthentication(redisURI, socketConfiguration); |
| 615 | + |
| 616 | + return socketConfiguration; |
| 617 | + } |
| 618 | + |
| 619 | + /** |
| 620 | + * Converts a {@link RedisURI} to its corresponding {@link RedisStandaloneConfiguration}. |
| 621 | + * |
| 622 | + * @param redisURI the uri containing the Redis connection info |
| 623 | + * @return a {@link RedisStandaloneConfiguration} representing the connection information in the Redis URI. |
| 624 | + * @since 2.6 |
| 625 | + */ |
| 626 | + public static RedisStandaloneConfiguration redisUriToStandaloneConfiguration(RedisURI redisURI) { |
| 627 | + |
| 628 | + Assert.notNull(redisURI, "RedisURI is required"); |
| 629 | + |
| 630 | + RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration(); |
| 631 | + standaloneConfiguration.setHostName(redisURI.getHost()); |
| 632 | + standaloneConfiguration.setPort(redisURI.getPort()); |
| 633 | + standaloneConfiguration.setDatabase(redisURI.getDatabase()); |
| 634 | + |
| 635 | + applyAuthentication(redisURI, standaloneConfiguration); |
| 636 | + |
| 637 | + return standaloneConfiguration; |
| 638 | + } |
| 639 | + |
| 640 | + private static void applyAuthentication(RedisURI redisURI, RedisConfiguration.WithAuthentication redisConfiguration) { |
| 641 | + if (StringUtils.hasText(redisURI.getUsername())) { |
| 642 | + redisConfiguration.setUsername(redisURI.getUsername()); |
| 643 | + } |
| 644 | + if (redisURI.getPassword() != null) { |
| 645 | + redisConfiguration.setPassword(redisURI.getPassword()); |
| 646 | + } |
| 647 | + } |
| 648 | + |
538 | 649 | public static byte[] toBytes(@Nullable String source) {
|
539 | 650 | if (source == null) {
|
540 | 651 | return null;
|
|
0 commit comments