Skip to content

Commit b1ae357

Browse files
authored
feat: Add RefreshTopologyFromInitialNodes (#126)
Signed-off-by: currantw <taylor.curran@improving.com>
1 parent d484024 commit b1ae357

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

sources/Valkey.Glide/ConnectionConfiguration.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@ internal record ConnectionConfig
2525
public Protocol? Protocol;
2626
public string? ClientName;
2727
public bool LazyConnect;
28+
public bool RefreshTopologyFromInitialNodes;
2829

2930
internal FFI.ConnectionConfig ToFfi() =>
30-
new(Addresses, TlsMode, ClusterMode, (uint?)RequestTimeout?.TotalMilliseconds, (uint?)ConnectionTimeout?.TotalMilliseconds, ReadFrom, RetryStrategy, AuthenticationInfo, DatabaseId, Protocol, ClientName, LazyConnect);
31+
new(
32+
Addresses,
33+
TlsMode,
34+
ClusterMode,
35+
(uint?)RequestTimeout?.TotalMilliseconds,
36+
(uint?)ConnectionTimeout?.TotalMilliseconds,
37+
ReadFrom,
38+
RetryStrategy,
39+
AuthenticationInfo,
40+
DatabaseId,
41+
Protocol,
42+
ClientName,
43+
LazyConnect,
44+
RefreshTopologyFromInitialNodes
45+
);
3146
}
3247

3348
/// <summary>
@@ -640,6 +655,30 @@ public class ClusterClientConfigurationBuilder : ClientConfigurationBuilder<Clus
640655
/// </summary>
641656
public ClusterClientConfigurationBuilder() : base(true) { }
642657

658+
#region Refresh Topology
659+
/// <summary>
660+
/// Enables refreshing the cluster topology using only the initial nodes.
661+
/// <para />
662+
/// When this option is enabled, all topology updates (both the periodic checks and on-demand
663+
/// refreshes triggered by topology changes) will query only the initial nodes provided when
664+
/// creating the client, rather than using the internal cluster view.
665+
/// <para />
666+
/// If not set, defaults to <c>false</c> (uses internal cluster view for topology refresh).
667+
/// </summary>
668+
public bool RefreshTopologyFromInitialNodes
669+
{
670+
get => Config.RefreshTopologyFromInitialNodes;
671+
set => Config.RefreshTopologyFromInitialNodes = value;
672+
}
673+
674+
/// <inheritdoc cref="RefreshTopologyFromInitialNodes" />
675+
public ClusterClientConfigurationBuilder WithRefreshTopologyFromInitialNodes(bool refreshTopologyFromInitialNodes)
676+
{
677+
RefreshTopologyFromInitialNodes = refreshTopologyFromInitialNodes;
678+
return this;
679+
}
680+
#endregion
681+
643682
/// <summary>
644683
/// Complete the configuration with given settings.
645684
/// </summary>

sources/Valkey.Glide/Internals/FFI.structs.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ public ConnectionConfig(
213213
uint databaseId,
214214
ConnectionConfiguration.Protocol? protocol,
215215
string? clientName,
216-
bool lazyConnect = false)
216+
bool lazyConnect = false,
217+
bool refreshTopologyFromInitialNodes = false)
217218
{
218219
_addresses = addresses;
219220
_request = new()
@@ -237,6 +238,7 @@ public ConnectionConfig(
237238
Protocol = protocol ?? default,
238239
ClientName = clientName,
239240
LazyConnect = lazyConnect,
241+
RefreshTopologyFromInitialNodes = refreshTopologyFromInitialNodes,
240242
};
241243
}
242244

@@ -785,6 +787,8 @@ private struct ConnectionRequest
785787
public string? ClientName;
786788
[MarshalAs(UnmanagedType.U1)]
787789
public bool LazyConnect;
790+
[MarshalAs(UnmanagedType.U1)]
791+
public bool RefreshTopologyFromInitialNodes;
788792
// TODO more config params, see ffi.rs
789793
}
790794

tests/Valkey.Glide.UnitTests/ConnectionConfigurationTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void WithAuthentication_PasswordOnly()
5050
}
5151

5252
[Fact]
53-
public void WithAuthentication_UsernameIamAuthConfig_ConfiguresCorrectly()
53+
public void WithAuthentication_UsernameIamAuthConfig()
5454
{
5555
var iamConfig = new IamAuthConfig(ClusterName, ServiceType.ElastiCache, Region, RefreshIntervalSeconds);
5656
var builder = new StandaloneClientConfigurationBuilder();
@@ -172,4 +172,30 @@ public void WithCredentials_MultipleCalls_LastWins()
172172
Assert.Equal(FFI.ServiceType.MemoryDB, iamCredentials.ServiceType);
173173
Assert.False(iamCredentials.HasRefreshIntervalSeconds);
174174
}
175+
176+
[Fact]
177+
public void RefreshTopologyFromInitialNodes_Default()
178+
{
179+
var builder = new ClusterClientConfigurationBuilder();
180+
var config = builder.Build();
181+
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
182+
}
183+
184+
[Fact]
185+
public void RefreshTopologyFromInitialNodes_True()
186+
{
187+
var builder = new ClusterClientConfigurationBuilder();
188+
builder.WithRefreshTopologyFromInitialNodes(true);
189+
var config = builder.Build();
190+
Assert.True(config.Request.RefreshTopologyFromInitialNodes);
191+
}
192+
193+
[Fact]
194+
public void RefreshTopologyFromInitialNodes_False()
195+
{
196+
var builder = new ClusterClientConfigurationBuilder();
197+
builder.WithRefreshTopologyFromInitialNodes(false);
198+
var config = builder.Build();
199+
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
200+
}
175201
}

0 commit comments

Comments
 (0)