Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion sources/Valkey.Glide/ConnectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@ internal record ConnectionConfig
public Protocol? Protocol;
public string? ClientName;
public bool LazyConnect;
public bool RefreshTopologyFromInitialNodes;

internal FFI.ConnectionConfig ToFfi() =>
new(Addresses, TlsMode, ClusterMode, (uint?)RequestTimeout?.TotalMilliseconds, (uint?)ConnectionTimeout?.TotalMilliseconds, ReadFrom, RetryStrategy, AuthenticationInfo, DatabaseId, Protocol, ClientName, LazyConnect);
new(
Addresses,
TlsMode,
ClusterMode,
(uint?)RequestTimeout?.TotalMilliseconds,
(uint?)ConnectionTimeout?.TotalMilliseconds,
ReadFrom,
RetryStrategy,
AuthenticationInfo,
DatabaseId,
Protocol,
ClientName,
LazyConnect,
RefreshTopologyFromInitialNodes
);
}

/// <summary>
Expand Down Expand Up @@ -640,6 +655,30 @@ public class ClusterClientConfigurationBuilder : ClientConfigurationBuilder<Clus
/// </summary>
public ClusterClientConfigurationBuilder() : base(true) { }

#region Refresh Topology
/// <summary>
/// Enables refreshing the cluster topology using only the initial nodes.
/// <para />
/// When this option is enabled, all topology updates (both the periodic checks and on-demand
/// refreshes triggered by topology changes) will query only the initial nodes provided when
/// creating the client, rather than using the internal cluster view.
/// <para />
/// If not set, defaults to <c>false</c> (uses internal cluster view for topology refresh).
/// </summary>
public bool RefreshTopologyFromInitialNodes
{
get => Config.RefreshTopologyFromInitialNodes;
set => Config.RefreshTopologyFromInitialNodes = value;
}

/// <inheritdoc cref="RefreshTopologyFromInitialNodes" />
public ClusterClientConfigurationBuilder WithRefreshTopologyFromInitialNodes(bool refreshTopologyFromInitialNodes)
{
RefreshTopologyFromInitialNodes = refreshTopologyFromInitialNodes;
return this;
}
#endregion

/// <summary>
/// Complete the configuration with given settings.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion sources/Valkey.Glide/Internals/FFI.structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ public ConnectionConfig(
uint databaseId,
ConnectionConfiguration.Protocol? protocol,
string? clientName,
bool lazyConnect = false)
bool lazyConnect = false,
bool refreshTopologyFromInitialNodes = false)
{
_addresses = addresses;
_request = new()
Expand All @@ -237,6 +238,7 @@ public ConnectionConfig(
Protocol = protocol ?? default,
ClientName = clientName,
LazyConnect = lazyConnect,
RefreshTopologyFromInitialNodes = refreshTopologyFromInitialNodes,
};
}

Expand Down Expand Up @@ -785,6 +787,8 @@ private struct ConnectionRequest
public string? ClientName;
[MarshalAs(UnmanagedType.U1)]
public bool LazyConnect;
[MarshalAs(UnmanagedType.U1)]
public bool RefreshTopologyFromInitialNodes;
// TODO more config params, see ffi.rs
}

Expand Down
28 changes: 27 additions & 1 deletion tests/Valkey.Glide.UnitTests/ConnectionConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void WithAuthentication_PasswordOnly()
}

[Fact]
public void WithAuthentication_UsernameIamAuthConfig_ConfiguresCorrectly()
public void WithAuthentication_UsernameIamAuthConfig()
{
var iamConfig = new IamAuthConfig(ClusterName, ServiceType.ElastiCache, Region, RefreshIntervalSeconds);
var builder = new StandaloneClientConfigurationBuilder();
Expand Down Expand Up @@ -172,4 +172,30 @@ public void WithCredentials_MultipleCalls_LastWins()
Assert.Equal(FFI.ServiceType.MemoryDB, iamCredentials.ServiceType);
Assert.False(iamCredentials.HasRefreshIntervalSeconds);
}

[Fact]
public void RefreshTopologyFromInitialNodes_Default()
{
var builder = new ClusterClientConfigurationBuilder();
var config = builder.Build();
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
}

[Fact]
public void RefreshTopologyFromInitialNodes_True()
{
var builder = new ClusterClientConfigurationBuilder();
builder.WithRefreshTopologyFromInitialNodes(true);
var config = builder.Build();
Assert.True(config.Request.RefreshTopologyFromInitialNodes);
}

[Fact]
public void RefreshTopologyFromInitialNodes_False()
{
var builder = new ClusterClientConfigurationBuilder();
builder.WithRefreshTopologyFromInitialNodes(false);
var config = builder.Build();
Assert.False(config.Request.RefreshTopologyFromInitialNodes);
}
}
Loading