Skip to content
Closed
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
30 changes: 28 additions & 2 deletions src/StackExchange.Redis/PhysicalBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,39 @@ internal bool TryEnqueue(List<Message> messages, bool isReplica)

if (isDisposed) throw new ObjectDisposedException(Name);

if (!IsConnected)
if (!IsConnected || NeedsReconnect)
{
// During reconnection (e.g. MOVED-to-same-endpoint), queue messages to the backlog
// so they can be sent once the connection is re-established.
// This matches the behavior of TryWriteAsync/TryWriteSync for individual commands.
if (Multiplexer.RawConfig.BacklogPolicy.QueueWhileDisconnected)
{
foreach (var message in messages)
{
message.SetEnqueued(null);
BacklogEnqueue(message);
}
StartBacklogProcessor();
return true;
}
return false;
}

var physical = this.physical;
if (physical == null) return false;
if (physical == null)
{
if (Multiplexer.RawConfig.BacklogPolicy.QueueWhileDisconnected)
{
foreach (var message in messages)
{
message.SetEnqueued(null);
BacklogEnqueue(message);
}
StartBacklogProcessor();
return true;
}
return false;
}
foreach (var message in messages)
{
// deliberately not taking a single lock here; we don't care if
Expand Down
7 changes: 7 additions & 0 deletions src/StackExchange.Redis/RedisBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public void Execute()
foreach (var message in snapshot)
{
var server = multiplexer.SelectServer(message);
// If no server found and we're allowed to queue while disconnected (e.g. during
// MOVED-triggered reconnection), retry with allowDisconnected to find the server
// so we can queue batch messages to its backlog.
if (server == null && multiplexer.RawConfig.BacklogPolicy.QueueWhileDisconnected)
{
server = multiplexer.ServerSelectionStrategy.Select(message, allowDisconnected: true);
}
if (server == null)
{
FailNoServer(multiplexer, snapshot);
Expand Down
Loading