Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/CommandMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StackExchange.Redis
/// <summary>
/// Represents the commands mapped on a particular configuration.
/// </summary>
public sealed class CommandMap
public sealed class CommandMap // TODO: (RESP3) add HELLO command here?
{
private readonly CommandBytes[] map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public static void AddProvider(DefaultOptionsProvider provider)
/// </summary>
public virtual TimeSpan KeepAliveInterval => TimeSpan.FromSeconds(60);

/// <summary>
/// Which Resp protocol to use (default is RESP 2).
/// </summary>
public virtual string Protocol => "2";

/// <summary>
/// Type of proxy to use (if any); for example <see cref="Proxy.Twemproxy"/>.
/// </summary>
Expand Down
18 changes: 17 additions & 1 deletion src/StackExchange.Redis/ConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ internal const string
User = "user",
Password = "password",
PreserveAsyncOrder = "preserveAsyncOrder",
Protocol = "protocol",
Proxy = "proxy",
ResolveDns = "resolveDns",
ResponseTimeout = "responseTimeout",
Expand Down Expand Up @@ -116,6 +117,7 @@ internal const string
User,
Password,
PreserveAsyncOrder,
Protocol,
Proxy,
ResolveDns,
ServiceName,
Expand Down Expand Up @@ -144,7 +146,7 @@ public static string TryNormalize(string value)
private bool? allowAdmin, abortOnConnectFail, resolveDns, ssl, checkCertificateRevocation,
includeDetailInExceptions, includePerformanceCountersInExceptions;

private string? tieBreaker, sslHost, configChannel;
private string? tieBreaker, sslHost, configChannel, protocol;

private TimeSpan? heartbeatInterval;

Expand Down Expand Up @@ -449,6 +451,15 @@ public bool PreserveAsyncOrder
set { }
}

/// <summary>
/// Which Resp protocol to use (default is RESP 2).
/// </summary>
public string Protocol
{
get => protocol ?? Defaults.Protocol;
set => protocol = value;
}

/// <summary>
/// Type of proxy to use (if any); for example <see cref="Proxy.Twemproxy"/>.
/// </summary>
Expand Down Expand Up @@ -632,6 +643,7 @@ public static ConfigurationOptions Parse(string configuration, bool ignoreUnknow
configChannel = configChannel,
abortOnConnectFail = abortOnConnectFail,
resolveDns = resolveDns,
protocol = protocol,
proxy = proxy,
commandMap = commandMap,
CertificateValidationCallback = CertificateValidationCallback,
Expand Down Expand Up @@ -727,6 +739,7 @@ public string ToString(bool includePassword)
Append(sb, OptionKeys.ResolveDns, resolveDns);
Append(sb, OptionKeys.ChannelPrefix, (string?)ChannelPrefix);
Append(sb, OptionKeys.ConnectRetry, connectRetry);
Append(sb, OptionKeys.Protocol, protocol);
Append(sb, OptionKeys.Proxy, proxy);
Append(sb, OptionKeys.ConfigCheckSeconds, configCheckSeconds);
Append(sb, OptionKeys.ResponseTimeout, responseTimeout);
Expand Down Expand Up @@ -874,6 +887,9 @@ private ConfigurationOptions DoParse(string configuration, bool ignoreUnknown)
case OptionKeys.SslHost:
SslHost = value;
break;
case OptionKeys.Protocol:
Protocol = value;
break;
case OptionKeys.Proxy:
Proxy = OptionKeys.ParseProxy(key, value);
break;
Expand Down
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/ConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public bool IncludePerformanceCountersInExceptions
/// </summary>
public string Configuration => RawConfig.ToString();

/// <summary>
/// Gets the RESP protocol in use.
/// </summary>
public string Protocol => RawConfig.Protocol;

/// <summary>
/// Indicates whether any servers are connected.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/StackExchange.Redis/Enums/RedisCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal enum RedisCommand
GETSET,

HDEL,
HELLO,
HEXISTS,
HGET,
HGETALL,
Expand Down Expand Up @@ -279,6 +280,7 @@ internal static bool IsPrimaryOnly(this RedisCommand command)
case RedisCommand.GETEX:
case RedisCommand.GETSET:
case RedisCommand.HDEL:
case RedisCommand.HELLO:
case RedisCommand.HINCRBY:
case RedisCommand.HINCRBYFLOAT:
case RedisCommand.HMSET:
Expand Down
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/Interfaces/IConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public interface IConnectionMultiplexer : IDisposable, IAsyncDisposable
/// </summary>
string Configuration { get; }

/// <summary>
/// Gets the RESP protocol in use.
/// </summary>
public string Protocol { get; }

/// <summary>
/// Gets the timeout associated with the connections.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ StackExchange.Redis.ConfigurationOptions.Password.get -> string?
StackExchange.Redis.ConfigurationOptions.Password.set -> void
StackExchange.Redis.ConfigurationOptions.PreserveAsyncOrder.get -> bool
StackExchange.Redis.ConfigurationOptions.PreserveAsyncOrder.set -> void
StackExchange.Redis.ConfigurationOptions.Protocol.get -> string!
StackExchange.Redis.ConfigurationOptions.Protocol.set -> void
StackExchange.Redis.ConfigurationOptions.Proxy.get -> StackExchange.Redis.Proxy
StackExchange.Redis.ConfigurationOptions.Proxy.set -> void
StackExchange.Redis.ConfigurationOptions.ReconnectRetryPolicy.get -> StackExchange.Redis.IReconnectRetryPolicy!
Expand Down Expand Up @@ -349,6 +351,7 @@ StackExchange.Redis.ConnectionMultiplexer.IsConnecting.get -> bool
StackExchange.Redis.ConnectionMultiplexer.OperationCount.get -> long
StackExchange.Redis.ConnectionMultiplexer.PreserveAsyncOrder.get -> bool
StackExchange.Redis.ConnectionMultiplexer.PreserveAsyncOrder.set -> void
StackExchange.Redis.ConnectionMultiplexer.Protocol.get -> string!
StackExchange.Redis.ConnectionMultiplexer.PublishReconfigure(StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long
StackExchange.Redis.ConnectionMultiplexer.PublishReconfigureAsync(StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task<long>!
StackExchange.Redis.ConnectionMultiplexer.ReconfigureAsync(string! reason) -> System.Threading.Tasks.Task<bool>!
Expand Down Expand Up @@ -488,6 +491,7 @@ StackExchange.Redis.IConnectionMultiplexer.IsConnecting.get -> bool
StackExchange.Redis.IConnectionMultiplexer.OperationCount.get -> long
StackExchange.Redis.IConnectionMultiplexer.PreserveAsyncOrder.get -> bool
StackExchange.Redis.IConnectionMultiplexer.PreserveAsyncOrder.set -> void
StackExchange.Redis.IConnectionMultiplexer.Protocol.get -> string!
StackExchange.Redis.IConnectionMultiplexer.PublishReconfigure(StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long
StackExchange.Redis.IConnectionMultiplexer.PublishReconfigureAsync(StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task<long>!
StackExchange.Redis.IConnectionMultiplexer.RegisterProfiler(System.Func<StackExchange.Redis.Profiling.ProfilingSession!>! profilingSessionProvider) -> void
Expand Down Expand Up @@ -1781,6 +1785,7 @@ virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.IncludeDetailIn
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.IncludePerformanceCountersInExceptions.get -> bool
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.IsMatch(System.Net.EndPoint! endpoint) -> bool
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.KeepAliveInterval.get -> System.TimeSpan
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.Protocol.get -> string!
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.Proxy.get -> StackExchange.Redis.Proxy
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.ReconnectRetryPolicy.get -> StackExchange.Redis.IReconnectRetryPolicy?
virtual StackExchange.Redis.Configuration.DefaultOptionsProvider.ResolveDns.get -> bool
Expand Down
8 changes: 8 additions & 0 deletions src/StackExchange.Redis/ServerEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,14 @@ private async Task HandshakeAsync(PhysicalConnection connection, LogProxy? log)
}
}

if (Multiplexer.Protocol == "3")
{
log?.WriteLine($"{Format.ToString(this)}: Setting RESP protocol to RESP {Multiplexer.Protocol}");
msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.HELLO, (RedisValue)Multiplexer.Protocol);
msg.SetInternalCall();
await WriteDirectOrQueueFireAndForgetAsync(connection, msg, ResultProcessor.DemandOK).ForAwait();
}

var bridge = connection.BridgeCouldBeNull;
if (bridge == null)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/StackExchange.Redis.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,20 @@ public void ThreadPoolManagerIsDetected()
Assert.Same(PipeScheduler.ThreadPool, conn.SocketManager?.Scheduler);
}

[Fact]
public void Resp3Test()
{
var config = new ConfigurationOptions
{
Protocol = "3"
};

var conn = ConnectionMultiplexer.Connect(config);
var db = conn.GetDatabase();
db.Ping();
db.Ping();
}

[Fact]
public void DefaultThreadPoolManagerIsDetected()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public bool IgnoreConnect

public string Configuration => _inner.Configuration;

public string Protocol => _inner.Protocol;

public int TimeoutMilliseconds => _inner.TimeoutMilliseconds;

public long OperationCount => _inner.OperationCount;
Expand Down