|
16 | 16 | package org.springframework.data.redis.connection.lettuce;
|
17 | 17 |
|
18 | 18 | import io.lettuce.core.RedisException;
|
| 19 | +import io.lettuce.core.RedisURI; |
19 | 20 | import io.lettuce.core.api.StatefulConnection;
|
20 | 21 | import io.lettuce.core.api.sync.BaseRedisCommands;
|
21 | 22 | import io.lettuce.core.cluster.RedisClusterClient;
|
|
26 | 27 | import io.lettuce.core.codec.RedisCodec;
|
27 | 28 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
28 | 29 |
|
| 30 | +import java.time.Duration; |
29 | 31 | import java.util.ArrayList;
|
30 | 32 | import java.util.Collection;
|
31 | 33 | import java.util.LinkedHashMap;
|
@@ -65,36 +67,47 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
65 | 67 | private final RedisClusterClient clusterClient;
|
66 | 68 | private ClusterCommandExecutor clusterCommandExecutor;
|
67 | 69 | private ClusterTopologyProvider topologyProvider;
|
68 |
| - private final boolean disposeClusterCommandExecutorOnClose; |
| 70 | + private boolean disposeClusterCommandExecutorOnClose; |
69 | 71 |
|
70 | 72 | /**
|
71 |
| - * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient}. |
| 73 | + * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient} with default |
| 74 | + * {@link RedisURI#DEFAULT_TIMEOUT_DURATION timeout} and a fresh {@link ClusterCommandExecutor} that gets destroyed on |
| 75 | + * close. |
72 | 76 | *
|
73 | 77 | * @param clusterClient must not be {@literal null}.
|
74 | 78 | */
|
75 | 79 | public LettuceClusterConnection(RedisClusterClient clusterClient) {
|
76 | 80 |
|
77 |
| - super(null, 100, clusterClient, null, 0); |
| 81 | + this(clusterClient, RedisURI.DEFAULT_TIMEOUT_DURATION, |
| 82 | + new ClusterCommandExecutor(new LettuceClusterTopologyProvider(clusterClient), |
| 83 | + new LettuceClusterNodeResourceProvider(clusterClient), exceptionConverter)); |
78 | 84 |
|
79 |
| - Assert.notNull(clusterClient, "RedisClusterClient must not be null."); |
80 |
| - |
81 |
| - this.clusterClient = clusterClient; |
82 |
| - topologyProvider = new LettuceClusterTopologyProvider(clusterClient); |
83 |
| - clusterCommandExecutor = new ClusterCommandExecutor(topologyProvider, |
84 |
| - new LettuceClusterNodeResourceProvider(clusterClient), exceptionConverter); |
85 |
| - disposeClusterCommandExecutorOnClose = true; |
| 85 | + this.disposeClusterCommandExecutorOnClose = true; |
86 | 86 | }
|
87 | 87 |
|
88 | 88 | /**
|
89 |
| - * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient} running commands across the cluster |
90 |
| - * via given {@link ClusterCommandExecutor}. |
| 89 | + * Creates new {@link LettuceClusterConnection} with default {@link RedisURI#DEFAULT_TIMEOUT_DURATION timeout} using |
| 90 | + * {@link RedisClusterClient} running commands across the cluster via given {@link ClusterCommandExecutor}. |
91 | 91 | *
|
92 | 92 | * @param clusterClient must not be {@literal null}.
|
93 | 93 | * @param executor must not be {@literal null}.
|
94 | 94 | */
|
95 | 95 | public LettuceClusterConnection(RedisClusterClient clusterClient, ClusterCommandExecutor executor) {
|
| 96 | + this(clusterClient, RedisURI.DEFAULT_TIMEOUT_DURATION, executor); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Creates new {@link LettuceClusterConnection} with given command {@code timeout} using {@link RedisClusterClient} |
| 101 | + * running commands across the cluster via given {@link ClusterCommandExecutor}. |
| 102 | + * |
| 103 | + * @param clusterClient must not be {@literal null}. |
| 104 | + * @param timeout must not be {@literal null}. |
| 105 | + * @param executor must not be {@literal null}. |
| 106 | + * @since 2.0 |
| 107 | + */ |
| 108 | + public LettuceClusterConnection(RedisClusterClient clusterClient, Duration timeout, ClusterCommandExecutor executor) { |
96 | 109 |
|
97 |
| - super(null, 100, clusterClient, null, 0); |
| 110 | + super(null, timeout.toMillis(), clusterClient, null, 0); |
98 | 111 |
|
99 | 112 | Assert.notNull(clusterClient, "RedisClusterClient must not be null.");
|
100 | 113 | Assert.notNull(executor, "ClusterCommandExecutor must not be null.");
|
|
0 commit comments