Skip to content

Commit fbd5836

Browse files
C#: Client configuration (#3321)
--------- Signed-off-by: Yury-Fridlyand <[email protected]> Co-authored-by: Edward Liang <[email protected]>
1 parent f57543c commit fbd5836

File tree

11 files changed

+883
-65
lines changed

11 files changed

+883
-65
lines changed

benchmarks/csharp/Program.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
using StackExchange.Redis;
1414

15+
using static Glide.ConnectionConfiguration;
16+
1517
public static class MainClass
1618
{
1719
private enum ChosenAction { GET_NON_EXISTING, GET_EXISTING, SET };
@@ -49,11 +51,6 @@ public class CommandLineOptions
4951

5052
private static string GetAddressForStackExchangeRedis(string host, bool useTLS) => $"{GetAddress(host)},ssl={useTLS}";
5153

52-
private static string GetAddressWithRedisPrefix(string host, bool useTLS)
53-
{
54-
string protocol = useTLS ? "rediss" : "redis";
55-
return $"{protocol}://{GetAddress(host)}";
56-
}
5754
private const double PROB_GET = 0.8;
5855

5956
private const double PROB_GET_EXISTING_KEY = 0.8;
@@ -95,7 +92,7 @@ private static double Percentile(double[] sequence, double excelPercentile)
9592
}
9693
}
9794

98-
private static double CalculateLatency(IEnumerable<double> latency_list, double percentile_point) => Math.Round(Percentile(latency_list.ToArray(), percentile_point), 2);
95+
private static double CalculateLatency(IEnumerable<double> latency_list, double percentile_point) => Math.Round(Percentile([.. latency_list], percentile_point), 2);
9996

10097
private static void PrintResults(string resultsFile)
10198
{
@@ -263,7 +260,9 @@ private static async Task RunWithParameters(int total_commands,
263260
{
264261
ClientWrapper[] clients = await CreateClients(clientCount, () =>
265262
{
266-
BaseClient glide_client = new GlideClient(host, PORT, useTLS);
263+
StandaloneClientConfiguration config = new StandaloneClientConfigurationBuilder()
264+
.WithAddress(host, PORT).WithTls(useTLS).Build();
265+
BaseClient glide_client = new GlideClient(config);
267266
return Task.FromResult<(Func<string, Task<string?>>, Func<string, string, Task>, Action)>(
268267
(async (key) => await glide_client.Get(key),
269268
async (key, value) => await glide_client.Set(key, value),

csharp/lib/BaseClient.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
using Glide.Commands;
77
using Glide.Internals;
88

9+
using static Glide.ConnectionConfiguration;
10+
911
namespace Glide;
1012

1113
public abstract class BaseClient : IDisposable, IStringBaseCommands
1214
{
1315
#region public methods
14-
protected BaseClient(string host, uint port, bool useTLS)
16+
protected BaseClient(BaseClientConfiguration config)
1517
{
1618
_successCallbackDelegate = SuccessCallback;
1719
nint successCallbackPointer = Marshal.GetFunctionPointerForDelegate(_successCallbackDelegate);
1820
_failureCallbackDelegate = FailureCallback;
1921
nint failureCallbackPointer = Marshal.GetFunctionPointerForDelegate(_failureCallbackDelegate);
20-
_clientPointer = CreateClientFfi(host, port, useTLS, successCallbackPointer, failureCallbackPointer);
22+
nint configPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ConnectionRequest)));
23+
Marshal.StructureToPtr(config.ToRequest(), configPtr, false);
24+
_clientPointer = CreateClientFfi(configPtr, successCallbackPointer, failureCallbackPointer);
25+
Marshal.FreeHGlobal(configPtr);
2126
if (_clientPointer == IntPtr.Zero)
2227
{
2328
throw new Exception("Failed creating a client");
@@ -123,7 +128,7 @@ private void FailureCallback(ulong index) =>
123128

124129
private delegate void IntAction(IntPtr arg);
125130
[DllImport("libglide_rs", CallingConvention = CallingConvention.Cdecl, EntryPoint = "create_client")]
126-
private static extern IntPtr CreateClientFfi(string host, uint port, bool useTLS, IntPtr successCallback, IntPtr failureCallback);
131+
private static extern IntPtr CreateClientFfi(IntPtr config, IntPtr successCallback, IntPtr failureCallback);
127132

128133
[DllImport("libglide_rs", CallingConvention = CallingConvention.Cdecl, EntryPoint = "close_client")]
129134
private static extern void CloseClientFfi(IntPtr client);

0 commit comments

Comments
 (0)