Skip to content

Commit 903e835

Browse files
committed
fix enum flags rendering; involves adding a net8.0 TFM, but that's LTS *anyway*, so: fine
also added appropriate [Obsolete] to respect transient net8.0 changes
1 parent b345d72 commit 903e835

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

src/StackExchange.Redis/ConfigurationOptions.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,17 @@ private static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X
357357
byte[] authorityData = authority.RawData;
358358
foreach (var chainElement in chain.ChainElements)
359359
{
360-
#if NET8_0_OR_GREATER
361-
#error TODO: use RawDataMemory (needs testing)
362-
#endif
363360
using var chainCert = chainElement.Certificate;
364-
if (!found && chainCert.RawData.SequenceEqual(authorityData))
361+
if (!found)
365362
{
366-
found = true;
363+
#if NET8_0_OR_GREATER
364+
if (chainCert.RawDataMemory.Span.SequenceEqual(authorityData))
365+
#else
366+
if (chainCert.RawData.SequenceEqual(authorityData))
367+
#endif
368+
{
369+
found = true;
370+
}
367371
}
368372
}
369373
return found;

src/StackExchange.Redis/Enums/CommandFlags.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,59 @@ public enum CommandFlags
3434
/// </summary>
3535
PreferMaster = 0,
3636

37+
#if NET8_0_OR_GREATER
38+
/// <summary>
39+
/// This operation should be performed on the replica if it is available, but will be performed on
40+
/// a primary if no replicas are available. Suitable for read operations only.
41+
/// </summary>
42+
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(PreferReplica) + " instead, this will be removed in 3.0.")]
43+
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
44+
PreferSlave = 8,
45+
#endif
46+
3747
/// <summary>
3848
/// This operation should only be performed on the primary.
3949
/// </summary>
4050
DemandMaster = 4,
4151

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

5062
/// <summary>
5163
/// This operation should be performed on the replica if it is available, but will be performed on
5264
/// a primary if no replicas are available. Suitable for read operations only.
5365
/// </summary>
5466
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
5567

68+
#if NET8_0_OR_GREATER
69+
/// <summary>
70+
/// This operation should only be performed on a replica. Suitable for read operations only.
71+
/// </summary>
72+
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(DemandReplica) + " instead, this will be removed in 3.0.")]
73+
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
74+
DemandSlave = 12,
75+
#endif
76+
5677
/// <summary>
5778
/// This operation should only be performed on a replica. Suitable for read operations only.
5879
/// </summary>
5980
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
6081

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

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

src/StackExchange.Redis/Exceptions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Runtime.Serialization;
34

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

26+
#if NET8_0_OR_GREATER
27+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
28+
[EditorBrowsable(EditorBrowsableState.Never)]
29+
#endif
2530
private RedisCommandException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
2631
}
2732

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

54+
#if NET8_0_OR_GREATER
55+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
56+
[EditorBrowsable(EditorBrowsableState.Never)]
57+
#endif
4958
private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
5059
{
5160
Commandstatus = info.GetValue("commandStatus", typeof(CommandStatus)) as CommandStatus? ?? CommandStatus.Unknown;
@@ -56,6 +65,10 @@ private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : ba
5665
/// </summary>
5766
/// <param name="info">Serialization info.</param>
5867
/// <param name="context">Serialization context.</param>
68+
#if NET8_0_OR_GREATER
69+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
70+
[EditorBrowsable(EditorBrowsableState.Never)]
71+
#endif
5972
public override void GetObjectData(SerializationInfo info, StreamingContext context)
6073
{
6174
base.GetObjectData(info, context);
@@ -107,6 +120,10 @@ public RedisConnectionException(ConnectionFailureType failureType, string messag
107120
/// </summary>
108121
public CommandStatus CommandStatus { get; }
109122

123+
#if NET8_0_OR_GREATER
124+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
125+
[EditorBrowsable(EditorBrowsableState.Never)]
126+
#endif
110127
private RedisConnectionException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
111128
{
112129
FailureType = (ConnectionFailureType)info.GetInt32("failureType");
@@ -118,6 +135,10 @@ private RedisConnectionException(SerializationInfo info, StreamingContext ctx) :
118135
/// </summary>
119136
/// <param name="info">Serialization info.</param>
120137
/// <param name="context">Serialization context.</param>
138+
#if NET8_0_OR_GREATER
139+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
140+
[EditorBrowsable(EditorBrowsableState.Never)]
141+
#endif
121142
public override void GetObjectData(SerializationInfo info, StreamingContext context)
122143
{
123144
base.GetObjectData(info, context);
@@ -150,6 +171,10 @@ public RedisException(string message, Exception? innerException) : base(message,
150171
/// </summary>
151172
/// <param name="info">Serialization info.</param>
152173
/// <param name="ctx">Serialization context.</param>
174+
#if NET8_0_OR_GREATER
175+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
176+
[EditorBrowsable(EditorBrowsableState.Never)]
177+
#endif
153178
protected RedisException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
154179
}
155180

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

193+
#if NET8_0_OR_GREATER
194+
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId)]
195+
[EditorBrowsable(EditorBrowsableState.Never)]
196+
#endif
168197
private RedisServerException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
169198
}
170199
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StackExchange.Redis;
2+
3+
internal static class Obsoletions
4+
{
5+
public const string LegacyFormatterImplMessage = "This API supports obsolete formatter-based serialization. It should not be called or extended by application code.";
6+
public const string LegacyFormatterImplDiagId = "SYSLIB0051";
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
StackExchange.Redis.ConfigurationOptions.SslClientAuthenticationOptions.get -> System.Func<string!, System.Net.Security.SslClientAuthenticationOptions!>?
2+
StackExchange.Redis.ConfigurationOptions.SslClientAuthenticationOptions.set -> void
3+
System.Runtime.CompilerServices.IsExternalInit (forwarded, contained in System.Runtime)

src/StackExchange.Redis/StackExchange.Redis.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Nullable>enable</Nullable>
44
<!-- extend the default lib targets for the main lib; mostly because of "vectors" -->
5-
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
66
<Description>High performance Redis client, incorporating both synchronous and asynchronous usage.</Description>
77
<AssemblyName>StackExchange.Redis</AssemblyName>
88
<AssemblyTitle>StackExchange.Redis</AssemblyTitle>

tests/StackExchange.Redis.Tests/FormatTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ public void ParseEndPoint(string data, EndPoint expected, string? expectedFormat
6262
[InlineData(CommandFlags.PreferReplica, "PreferReplica")] // 2-bit flag is hit-and-miss
6363
[InlineData(CommandFlags.DemandReplica, "DemandReplica")] // 2-bit flag is hit-and-miss
6464
#endif
65+
66+
#if NET8_0_OR_GREATER
67+
[InlineData(CommandFlags.PreferReplica | CommandFlags.FireAndForget, "FireAndForget, PreferReplica")] // 2-bit flag is hit-and-miss
68+
[InlineData(CommandFlags.DemandReplica | CommandFlags.FireAndForget, "FireAndForget, DemandReplica")] // 2-bit flag is hit-and-miss
69+
#else
6570
[InlineData(CommandFlags.PreferReplica | CommandFlags.FireAndForget, "PreferMaster, FireAndForget, PreferReplica")] // 2-bit flag is hit-and-miss
6671
[InlineData(CommandFlags.DemandReplica | CommandFlags.FireAndForget, "PreferMaster, FireAndForget, DemandReplica")] // 2-bit flag is hit-and-miss
72+
#endif
6773
public void CommandFlagsFormatting(CommandFlags value, string expected)
6874
=> Assert.Equal(expected, value.ToString());
6975

0 commit comments

Comments
 (0)