Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 7 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
<PackageVersion Include="System.Threading.Channels" Version="5.0.0" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />

<!-- Packages only used in the solution, upgrade at will -->
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.146" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.6.96" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="9.0.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="9.0.0" />
<!-- For binding redirect testing, main package gets this transitively -->
<PackageVersion Include="System.IO.Pipelines" Version="9.0.0" />
<PackageVersion Include="System.Runtime.Caching" Version="9.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion StackExchange.Redis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{73A5C363-CA1F-44C4-9A9B-EF791A76BA6A}"
ProjectSection(SolutionItems) = preProject
tests\.editorconfig = tests\.editorconfig
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Build.targets = tests\Directory.Build.targets
EndProjectSection
EndProject
Expand Down
10 changes: 5 additions & 5 deletions src/StackExchange.Redis/Interfaces/IServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public partial interface IServer : IRedis
/// <remarks><seealso href="https://redis.io/commands/client-kill"/></remarks>
void ClientKill(EndPoint endpoint, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="ClientKill(EndPoint, CommandFlags)"/>
/// <inheritdoc cref="ClientKill(System.Net.EndPoint, CommandFlags)"/>
Task ClientKillAsync(EndPoint endpoint, CommandFlags flags = CommandFlags.None);

/// <summary>
Expand All @@ -104,7 +104,7 @@ public partial interface IServer : IRedis
/// <remarks><seealso href="https://redis.io/commands/client-kill"/></remarks>
long ClientKill(long? id = null, ClientType? clientType = null, EndPoint? endpoint = null, bool skipMe = true, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="ClientKill(long?, ClientType?, EndPoint?, bool, CommandFlags)"/>
/// <inheritdoc cref="ClientKill(long?, ClientType?, System.Net.EndPoint?, bool, CommandFlags)"/>
Task<long> ClientKillAsync(long? id = null, ClientType? clientType = null, EndPoint? endpoint = null, bool skipMe = true, CommandFlags flags = CommandFlags.None);

/// <summary>
Expand Down Expand Up @@ -475,17 +475,17 @@ public partial interface IServer : IRedis
/// <remarks><seealso href="https://redis.io/commands/shutdown"/></remarks>
void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="ReplicaOfAsync(EndPoint, CommandFlags)"/>
/// <inheritdoc cref="ReplicaOfAsync(System.Net.EndPoint,CommandFlags)"/>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(ReplicaOfAsync) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="ReplicaOfAsync(EndPoint, CommandFlags)"/>
/// <inheritdoc cref="ReplicaOfAsync(System.Net.EndPoint,CommandFlags)"/>
[Obsolete("Starting with Redis version 5, Redis has moved to 'replica' terminology. Please use " + nameof(ReplicaOfAsync) + " instead, this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
Task SlaveOfAsync(EndPoint master, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="ReplicaOfAsync(EndPoint, CommandFlags)"/>
/// <inheritdoc cref="ReplicaOfAsync(System.Net.EndPoint,CommandFlags)"/>
[Obsolete("Please use " + nameof(ReplicaOfAsync) + ", this will be removed in 3.0.")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
void ReplicaOf(EndPoint master, CommandFlags flags = CommandFlags.None);
Expand Down
4 changes: 2 additions & 2 deletions src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[]? keys = nul

public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[]? keys = null, RedisValue[]? values = null, CommandFlags flags = CommandFlags.None) =>
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
Inner.ScriptEvaluateAsync(script, ToInner(keys), values, flags);
Inner.ScriptEvaluateAsync(script: script, keys: ToInner(keys), values: values, flags: flags);

public Task<RedisResult> ScriptEvaluateAsync(LuaScript script, object? parameters = null, CommandFlags flags = CommandFlags.None) =>
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
Expand All @@ -367,7 +367,7 @@ public Task<RedisResult> ScriptEvaluateReadOnlyAsync(byte[] hash, RedisKey[]? ke

public Task<RedisResult> ScriptEvaluateReadOnlyAsync(string script, RedisKey[]? keys = null, RedisValue[]? values = null, CommandFlags flags = CommandFlags.None) =>
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
Inner.ScriptEvaluateAsync(script, ToInner(keys), values, flags);
Inner.ScriptEvaluateAsync(script: script, keys: ToInner(keys), values: values, flags: flags);

public Task<long> SetAddAsync(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None) =>
Inner.SetAddAsync(ToInner(key), values, flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public RedisResult ScriptEvaluate(byte[] hash, RedisKey[]? keys = null, RedisVal

public RedisResult ScriptEvaluate(string script, RedisKey[]? keys = null, RedisValue[]? values = null, CommandFlags flags = CommandFlags.None) =>
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
Inner.ScriptEvaluate(script, ToInner(keys), values, flags);
Inner.ScriptEvaluate(script: script, keys: ToInner(keys), values: values, flags: flags);

public RedisResult ScriptEvaluate(LuaScript script, object? parameters = null, CommandFlags flags = CommandFlags.None) =>
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
Expand Down
8 changes: 4 additions & 4 deletions src/StackExchange.Redis/LuaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal void ExtractParameters(object? ps, RedisKey? keyPrefix, out RedisKey[]?
public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);
return db.ScriptEvaluate(ExecutableScript, keys, args, flags);
return db.ScriptEvaluate(script: ExecutableScript, keys: keys, values: args, flags: flags);
}

/// <summary>
Expand All @@ -161,7 +161,7 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);
return db.ScriptEvaluateAsync(ExecutableScript, keys, args, flags);
return db.ScriptEvaluateAsync(script: ExecutableScript, keys: keys, values: args, flags: flags);
}

/// <summary>
Expand Down Expand Up @@ -269,7 +269,7 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr
{
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);

return db.ScriptEvaluate(ExecutableScript, keys, args, flags);
return db.ScriptEvaluate(script: ExecutableScript, keys: keys, values: args, flags: flags);
}

/// <summary>
Expand All @@ -287,7 +287,7 @@ public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object? ps = null, Red
{
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);

return db.ScriptEvaluateAsync(ExecutableScript, keys, args, flags);
return db.ScriptEvaluateAsync(script: ExecutableScript, keys: keys, values: args, flags: flags);
}
}
}
4 changes: 2 additions & 2 deletions src/StackExchange.Redis/PhysicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,8 @@ internal async ValueTask<bool> ConnectedAsync(Socket? socket, ILogger? log, Sock
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
bridge.Multiplexer?.SetAuthSuspect(ex);
bridge.Multiplexer?.Logger?.LogError(ex, ex.Message);
bridge.Multiplexer.SetAuthSuspect(ex);
bridge.Multiplexer.Logger?.LogError(ex, ex.Message);
throw;
}
log?.LogInformation($"TLS connection established successfully using protocol: {ssl.SslProtocol}");
Expand Down
10 changes: 5 additions & 5 deletions src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ public virtual bool SetResult(PhysicalConnection connection, Message message, in
{
if (result.StartsWith(CommonReplies.NOAUTH))
{
bridge?.Multiplexer?.SetAuthSuspect(new RedisServerException("NOAUTH Returned - connection has not yet authenticated"));
bridge?.Multiplexer.SetAuthSuspect(new RedisServerException("NOAUTH Returned - connection has not yet authenticated"));
}
else if (result.StartsWith(CommonReplies.WRONGPASS))
{
bridge?.Multiplexer?.SetAuthSuspect(new RedisServerException(result.ToString()));
bridge?.Multiplexer.SetAuthSuspect(new RedisServerException(result.ToString()));
}

var server = bridge?.ServerEndPoint;
Expand All @@ -259,7 +259,7 @@ public virtual bool SetResult(PhysicalConnection connection, Message message, in
// no point sending back to same server, and no point sending to a dead server
if (!Equals(server?.EndPoint, endpoint))
{
if (bridge == null)
if (bridge is null)
{
// already toast
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public virtual bool SetResult(PhysicalConnection connection, Message message, in
{
bridge?.Multiplexer.OnErrorMessage(server.EndPoint, err);
}
bridge?.Multiplexer?.Trace("Completed with error: " + err + " (" + GetType().Name + ")", ToString());
bridge?.Multiplexer.Trace("Completed with error: " + err + " (" + GetType().Name + ")", ToString());
if (unableToConnectError)
{
ConnectionFail(message, ConnectionFailureType.UnableToConnect, err);
Expand All @@ -323,7 +323,7 @@ public virtual bool SetResult(PhysicalConnection connection, Message message, in
bool coreResult = SetResultCore(connection, message, result);
if (coreResult)
{
bridge?.Multiplexer?.Trace("Completed with success: " + result.ToString() + " (" + GetType().Name + ")", ToString());
bridge?.Multiplexer.Trace("Completed with success: " + result.ToString() + " (" + GetType().Name + ")", ToString());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/ServerEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ internal void OnFullyEstablished(PhysicalConnection connection, string source)
}
catch (Exception ex)
{
connection.RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex);
connection?.RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/StackExchange.Redis/StackExchange.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
</PropertyGroup>

<ItemGroup>
<!-- needed everywhere -->
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<!-- needed everywhere (with hack to override to LTS when possible) -->
<PackageReference Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="8.0"/>
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Pipelines.Sockets.Unofficial" />

<!-- built into .NET core now -->
Expand Down
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/TextWriterLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public TextWriterLogger(TextWriter writer, ILogger? wrapped)
_wrapped = wrapped;
}

#if NET8_0_OR_GREATER
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => NothingDisposable.Instance;
#else
public IDisposable BeginScope<TState>(TState state) => NothingDisposable.Instance;
#endif

public bool IsEnabled(LogLevel logLevel) => _writer is not null || _wrapped is not null;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/StackExchange.Redis.Tests/KeyPrefixedDatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ public void ScriptEvaluate_2()
RedisValue[] values = Array.Empty<RedisValue>();
RedisKey[] keys = new RedisKey[] { "a", "b" };
Expression<Predicate<RedisKey[]>> valid = _ => _.Length == 2 && _[0] == "prefix:a" && _[1] == "prefix:b";
prefixed.ScriptEvaluate("script", keys, values, CommandFlags.None);
mock.Received().ScriptEvaluate("script", Arg.Is(valid), values, CommandFlags.None);
prefixed.ScriptEvaluate(script: "script", keys: keys, values: values, flags: CommandFlags.None);
mock.Received().ScriptEvaluate(script: "script", keys: Arg.Is(valid), values: values, flags: CommandFlags.None);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/KeyPrefixedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public async Task ScriptEvaluateAsync_2()
RedisKey[] keys = new RedisKey[] { "a", "b" };
Expression<Predicate<RedisKey[]>> valid = _ => _.Length == 2 && _[0] == "prefix:a" && _[1] == "prefix:b";
await prefixed.ScriptEvaluateAsync("script", keys, values, CommandFlags.None);
await mock.Received().ScriptEvaluateAsync("script", Arg.Is(valid), values, CommandFlags.None);
await mock.Received().ScriptEvaluateAsync(script: "script", keys: Arg.Is(valid), values: values, flags: CommandFlags.None);
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions tests/StackExchange.Redis.Tests/LockingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public async Task TakeLockAndExtend(TestMode testMode)
Assert.Equal(right, await t4);
if (withTran) Assert.False(await t5!, "5");
Assert.Equal(right, await t6);
var ttl = (await t7).Value.TotalSeconds;
var ttl = (await t7)!.Value.TotalSeconds;
Assert.True(ttl > 0 && ttl <= 20, "7");
Assert.True(await t8, "8");
Assert.Equal(right, await t9);
ttl = (await t10).Value.TotalSeconds;
ttl = (await t10)!.Value.TotalSeconds;
Assert.True(ttl > 50 && ttl <= 60, "10");
Assert.True(await t11, "11");
Assert.Null((string?)await t12);
Expand Down Expand Up @@ -185,7 +185,7 @@ public async Task TestBasicLockNotTaken(TestMode testMode)
}
Assert.True(await taken!, "taken");
Assert.Equal("new-value", await newValue!);
var ttlValue = (await ttl!).Value.TotalSeconds;
var ttlValue = (await ttl!)!.Value.TotalSeconds;
Assert.True(ttlValue >= 8 && ttlValue <= 10, "ttl");

Assert.Equal(0, errorCount);
Expand All @@ -206,7 +206,7 @@ public async Task TestBasicLockTaken(TestMode testMode)

Assert.False(await taken, "taken");
Assert.Equal("old-value", await newValue);
var ttlValue = (await ttl).Value.TotalSeconds;
var ttlValue = (await ttl)!.Value.TotalSeconds;
Assert.True(ttlValue >= 18 && ttlValue <= 20, "ttl");
}
}
12 changes: 12 additions & 0 deletions tests/StackExchange.Redis.Tests/LoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public class TestWrapperLogger : ILogger

public TestWrapperLogger(ILogger toWrap) => Inner = toWrap;

#if NET8_0_OR_GREATER
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => Inner.BeginScope(state);
#else
public IDisposable BeginScope<TState>(TState state) => Inner.BeginScope(state);
#endif
public bool IsEnabled(LogLevel logLevel) => Inner.IsEnabled(logLevel);
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
Expand All @@ -86,7 +90,11 @@ private class TestMultiLogger : ILogger
private readonly ILogger[] _loggers;
public TestMultiLogger(params ILogger[] loggers) => _loggers = loggers;

#if NET8_0_OR_GREATER
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => throw new NotImplementedException();
#else
public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException();
#endif
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
Expand All @@ -106,7 +114,11 @@ private class TestLogger : ILogger
public TestLogger(LogLevel logLevel, TextWriter output) =>
(_logLevel, _output) = (logLevel, output);

#if NET8_0_OR_GREATER
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => throw new NotImplementedException();
#else
public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException();
#endif
public bool IsEnabled(LogLevel logLevel) => logLevel >= _logLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/RespProtocolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task CheckLuaResult(string script, RedisProtocol protocol, ResultTy
db.HashSet("key", "b", 2);
db.HashSet("key", "c", 3);
}
var result = await db.ScriptEvaluateAsync(script, flags: CommandFlags.NoScriptCache);
var result = await db.ScriptEvaluateAsync(script: script, flags: CommandFlags.NoScriptCache);
Assert.Equal(resp2, result.Resp2Type);
Assert.Equal(resp3, result.Resp3Type);

Expand Down
Loading
Loading