Skip to content

Commit

Permalink
fix enum flags rendering; involves adding a net8.0 TFM, but that's LT…
Browse files Browse the repository at this point in the history
…S *anyway*, so: fine

also added appropriate [Obsolete] to respect transient net8.0 changes
  • Loading branch information
mgravell committed Nov 26, 2024
1 parent b345d72 commit 903e835
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/StackExchange.Redis/ConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,17 @@ private static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X
byte[] authorityData = authority.RawData;
foreach (var chainElement in chain.ChainElements)
{
#if NET8_0_OR_GREATER
#error TODO: use RawDataMemory (needs testing)
#endif
using var chainCert = chainElement.Certificate;
if (!found && chainCert.RawData.SequenceEqual(authorityData))
if (!found)
{
found = true;
#if NET8_0_OR_GREATER
if (chainCert.RawDataMemory.Span.SequenceEqual(authorityData))
#else
if (chainCert.RawData.SequenceEqual(authorityData))
#endif
{
found = true;
}
}
}
return found;
Expand Down
23 changes: 23 additions & 0 deletions src/StackExchange.Redis/Enums/CommandFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,59 @@ public enum CommandFlags
/// </summary>
PreferMaster = 0,

#if NET8_0_OR_GREATER
/// <summary>
/// This operation should be performed on the replica if it is available, but will be performed on
/// a primary if no replicas are available. Suitable for read operations only.
/// </summary>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(PreferReplica) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
PreferSlave = 8,
#endif

/// <summary>
/// This operation should only be performed on the primary.
/// </summary>
DemandMaster = 4,

#if !NET8_0_OR_GREATER
/// <summary>
/// This operation should be performed on the replica if it is available, but will be performed on
/// a primary if no replicas are available. Suitable for read operations only.
/// </summary>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(PreferReplica) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
PreferSlave = 8,
#endif

/// <summary>
/// This operation should be performed on the replica if it is available, but will be performed on
/// a primary if no replicas are available. Suitable for read operations only.
/// </summary>
PreferReplica = 8, // note: we're using a 2-bit set here, which [Flags] formatting hates; position is doing the best we can for reasonable outcomes here

#if NET8_0_OR_GREATER
/// <summary>
/// This operation should only be performed on a replica. Suitable for read operations only.
/// </summary>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(DemandReplica) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
DemandSlave = 12,
#endif

/// <summary>
/// This operation should only be performed on a replica. Suitable for read operations only.
/// </summary>
DemandReplica = 12, // note: we're using a 2-bit set here, which [Flags] formatting hates; position is doing the best we can for reasonable outcomes here

#if !NET8_0_OR_GREATER
/// <summary>
/// This operation should only be performed on a replica. Suitable for read operations only.
/// </summary>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(DemandReplica) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
DemandSlave = 12,
#endif

// 16: reserved for additional "demand/prefer" options

Expand Down
29 changes: 29 additions & 0 deletions src/StackExchange.Redis/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace StackExchange.Redis
Expand All @@ -22,6 +23,10 @@ public RedisCommandException(string message) : base(message) { }
/// <param name="innerException">The inner exception.</param>
public RedisCommandException(string message, Exception innerException) : base(message, innerException) { }

#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
private RedisCommandException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}

Expand All @@ -46,6 +51,10 @@ public RedisTimeoutException(string message, CommandStatus commandStatus) : base
/// </summary>
public CommandStatus Commandstatus { get; }

#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
Commandstatus = info.GetValue("commandStatus", typeof(CommandStatus)) as CommandStatus? ?? CommandStatus.Unknown;
Expand All @@ -56,6 +65,10 @@ private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : ba
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Serialization context.</param>
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down Expand Up @@ -107,6 +120,10 @@ public RedisConnectionException(ConnectionFailureType failureType, string messag
/// </summary>
public CommandStatus CommandStatus { get; }

#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
private RedisConnectionException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
FailureType = (ConnectionFailureType)info.GetInt32("failureType");
Expand All @@ -118,6 +135,10 @@ private RedisConnectionException(SerializationInfo info, StreamingContext ctx) :
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Serialization context.</param>
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down Expand Up @@ -150,6 +171,10 @@ public RedisException(string message, Exception? innerException) : base(message,
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="ctx">Serialization context.</param>
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
protected RedisException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}

Expand All @@ -165,6 +190,10 @@ public sealed partial class RedisServerException : RedisException
/// <param name="message">The message for the exception.</param>
public RedisServerException(string message) : base(message) { }

#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
private RedisServerException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}
}
7 changes: 7 additions & 0 deletions src/StackExchange.Redis/Obsoletions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace StackExchange.Redis;

internal static class Obsoletions
{
public const string LegacyFormatterImplMessage = "This API supports obsolete formatter-based serialization. It should not be called or extended by application code.";
public const string LegacyFormatterImplDiagId = "SYSLIB0051";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
StackExchange.Redis.ConfigurationOptions.SslClientAuthenticationOptions.get -> System.Func<string!, System.Net.Security.SslClientAuthenticationOptions!>?
StackExchange.Redis.ConfigurationOptions.SslClientAuthenticationOptions.set -> void
System.Runtime.CompilerServices.IsExternalInit (forwarded, contained in System.Runtime)
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/StackExchange.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<!-- extend the default lib targets for the main lib; mostly because of "vectors" -->
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
<Description>High performance Redis client, incorporating both synchronous and asynchronous usage.</Description>
<AssemblyName>StackExchange.Redis</AssemblyName>
<AssemblyTitle>StackExchange.Redis</AssemblyTitle>
Expand Down
6 changes: 6 additions & 0 deletions tests/StackExchange.Redis.Tests/FormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ public void ParseEndPoint(string data, EndPoint expected, string? expectedFormat
[InlineData(CommandFlags.PreferReplica, "PreferReplica")] // 2-bit flag is hit-and-miss
[InlineData(CommandFlags.DemandReplica, "DemandReplica")] // 2-bit flag is hit-and-miss
#endif

#if NET8_0_OR_GREATER
[InlineData(CommandFlags.PreferReplica | CommandFlags.FireAndForget, "FireAndForget, PreferReplica")] // 2-bit flag is hit-and-miss
[InlineData(CommandFlags.DemandReplica | CommandFlags.FireAndForget, "FireAndForget, DemandReplica")] // 2-bit flag is hit-and-miss
#else
[InlineData(CommandFlags.PreferReplica | CommandFlags.FireAndForget, "PreferMaster, FireAndForget, PreferReplica")] // 2-bit flag is hit-and-miss
[InlineData(CommandFlags.DemandReplica | CommandFlags.FireAndForget, "PreferMaster, FireAndForget, DemandReplica")] // 2-bit flag is hit-and-miss
#endif
public void CommandFlagsFormatting(CommandFlags value, string expected)
=> Assert.Equal(expected, value.ToString());

Expand Down

0 comments on commit 903e835

Please sign in to comment.