Skip to content

Commit 352656e

Browse files
committed
Add refresh topology to cluster configuration builder and request struct.
Signed-off-by: currantw <taylor.curran@improving.com>
1 parent d03dbe3 commit 352656e

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
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>
@@ -584,6 +599,30 @@ public class ClusterClientConfigurationBuilder : ClientConfigurationBuilder<Clus
584599
{
585600
public ClusterClientConfigurationBuilder() : base(true) { }
586601

602+
#region Refresh Topology
603+
/// <summary>
604+
/// Enables refreshing the cluster topology using only the initial nodes.
605+
/// <para />
606+
/// When this option is enabled, all topology updates (both the periodic checks and on-demand
607+
/// refreshes triggered by topology changes) will query only the initial nodes provided when
608+
/// creating the client, rather than using the internal cluster view.
609+
/// <para />
610+
/// If not set, defaults to <c>false</c> (uses internal cluster view for topology refresh).
611+
/// </summary>
612+
public bool RefreshTopologyFromInitialNodes
613+
{
614+
get => Config.RefreshTopologyFromInitialNodes;
615+
set => Config.RefreshTopologyFromInitialNodes = value;
616+
}
617+
618+
/// <inheritdoc cref="RefreshTopologyFromInitialNodes" />
619+
public ClusterClientConfigurationBuilder WithRefreshTopologyFromInitialNodes(bool refreshTopologyFromInitialNodes)
620+
{
621+
RefreshTopologyFromInitialNodes = refreshTopologyFromInitialNodes;
622+
return this;
623+
}
624+
#endregion
625+
587626
/// <summary>
588627
/// Complete the configuration with given settings.
589628
/// </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

@@ -774,6 +776,8 @@ private struct ConnectionRequest
774776
public string? ClientName;
775777
[MarshalAs(UnmanagedType.U1)]
776778
public bool LazyConnect;
779+
[MarshalAs(UnmanagedType.U1)]
780+
public bool RefreshTopologyFromInitialNodes;
777781
// TODO more config params, see ffi.rs
778782
}
779783

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2+
3+
using Valkey.Glide.Internals;
4+
5+
using static Valkey.Glide.ConnectionConfiguration;
6+
7+
namespace Valkey.Glide.UnitTests;
8+
9+
public class ConnectionConfigurationTests
10+
{
11+
[Fact]
12+
public void RefreshTopologyFromInitialNodes()
13+
{
14+
ClusterClientConfigurationBuilder builder;
15+
ClusterClientConfiguration config;
16+
17+
// Default (false).
18+
builder = new ClusterClientConfigurationBuilder();
19+
config = builder.Build();
20+
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
21+
22+
// Set to true.
23+
builder = new ClusterClientConfigurationBuilder();
24+
builder.WithRefreshTopologyFromInitialNodes(true);
25+
config = builder.Build();
26+
Assert.True(config.Request.RefreshTopologyFromInitialNodes);
27+
28+
// Set to false.
29+
builder = new ClusterClientConfigurationBuilder();
30+
builder.WithRefreshTopologyFromInitialNodes(false);
31+
config = builder.Build();
32+
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
33+
}
34+
}

0 commit comments

Comments
 (0)