Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/StackExchange.Redis/ClusterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
if (node.IsMyself)
Origin = node.EndPoint;

if (nodeLookup.ContainsKey(node.EndPoint))
if (nodeLookup.TryGetValue(node.EndPoint, out var lookedUpNode))
{
// Deal with conflicting node entries for the same endpoint
// This can happen in dynamic environments when a node goes down and a new one is created
Expand All @@ -190,7 +190,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
// The node we're trying to add is probably about to become stale. Ignore it.
continue;
}
else if (!nodeLookup[node.EndPoint].IsConnected)
else if (!lookedUpNode.IsConnected)
{
// The node we registered previously is probably stale. Replace it with a known good node.
nodeLookup[node.EndPoint] = node;
Expand Down
9 changes: 6 additions & 3 deletions src/StackExchange.Redis/Configuration/LoggingTunnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ public override void Flush()

public override async Task FlushAsync(CancellationToken cancellationToken)
{
await _writes.FlushAsync().ForAwait();
var writesTask = _writes.FlushAsync().ForAwait();
await _inner.FlushAsync().ForAwait();
await writesTask;
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -608,8 +609,9 @@ public override void Write(byte[] buffer, int offset, int count)
}
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await _writes.WriteAsync(buffer, offset, count, cancellationToken).ForAwait();
var writesTask = _writes.WriteAsync(buffer, offset, count, cancellationToken).ForAwait();
await _inner.WriteAsync(buffer, offset, count, cancellationToken).ForAwait();
await writesTask;
}
#if NETCOREAPP3_0_OR_GREATER
public override void Write(ReadOnlySpan<byte> buffer)
Expand All @@ -619,8 +621,9 @@ public override void Write(ReadOnlySpan<byte> buffer)
}
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
{
await _writes.WriteAsync(buffer, cancellationToken).ForAwait();
var writesTask = _writes.WriteAsync(buffer, cancellationToken).ForAwait();
await _inner.WriteAsync(buffer, cancellationToken).ForAwait();
await writesTask;
}
#endif
}
Expand Down
8 changes: 3 additions & 5 deletions src/StackExchange.Redis/ConnectionMultiplexer.Sentinel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class ConnectionMultiplexer
{
internal EndPoint? currentSentinelPrimaryEndPoint;
internal Timer? sentinelPrimaryReconnectTimer;
internal Dictionary<string, ConnectionMultiplexer> sentinelConnectionChildren = new Dictionary<string, ConnectionMultiplexer>();
internal readonly Dictionary<string, ConnectionMultiplexer> sentinelConnectionChildren = new();
internal ConnectionMultiplexer? sentinelConnection;

/// <summary>
Expand Down Expand Up @@ -44,10 +44,8 @@ internal void InitializeSentinel(ILogger? log)
lock (sentinelConnectionChildren)
{
// Switch the primary if we have connections for that service
if (sentinelConnectionChildren.ContainsKey(messageParts[0]))
if (sentinelConnectionChildren.TryGetValue(messageParts[0], out ConnectionMultiplexer? child))
{
ConnectionMultiplexer child = sentinelConnectionChildren[messageParts[0]];

// Is the connection still valid?
if (child.IsDisposed)
{
Expand All @@ -57,7 +55,7 @@ internal void InitializeSentinel(ILogger? log)
}
else
{
SwitchPrimary(switchBlame, sentinelConnectionChildren[messageParts[0]]);
SwitchPrimary(switchBlame, child);
}
}
}
Expand Down
Loading