Skip to content

Commit

Permalink
Honor select disposition in transactions (#2322)
Browse files Browse the repository at this point in the history
* honor select disposition in transactions

* rearranging if/switch

* using server instead of multiplxer

* release notes
  • Loading branch information
slorello89 authored Dec 21, 2023
1 parent 0233585 commit e8b0006
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Current package versions:
- Fix [#2249](https://github.com/StackExchange/StackExchange.Redis/issues/2249): Properly handle a `fail` state (new `ClusterNode.IsFail` property) for `CLUSTER NODES` and expose `fail?` as a property (`IsPossiblyFail`) as well ([#2288 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2288))
- Adds: `IConnectionMultiplexer.ServerMaintenanceEvent` (was on `ConnectionMultiplexer` but not the interface) ([#2306 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2306))
- Adds: To timeout messages, additional debug information: `Sync-Ops` (synchronous operations), `Async-Ops` (asynchronous operations), and `Server-Connected-Seconds` (how long the connection in question has been connected, or `"n/a"`) ([#2300 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2300))

- Fix: [#2321](https://github.com/StackExchange/StackExchange.Redis/issues/2321): Honor disposition of select command in Command Map for transactions [(#2322 by slorello89)](https://github.com/StackExchange/StackExchange.Redis/pull/2322)

## 2.6.80

Expand Down
22 changes: 13 additions & 9 deletions src/StackExchange.Redis/RedisTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,24 @@ private void QueueMessage(Message message)
lock (SyncLock)
{
(_pending ??= new List<QueuedMessage>()).Add(queued);

switch (message.Command)
{
case RedisCommand.UNKNOWN:
case RedisCommand.EVAL:
case RedisCommand.EVALSHA:
// people can do very naughty things in an EVAL
// including change the DB; change it back to what we
// think it should be!
var sel = PhysicalConnection.GetSelectDatabaseCommand(message.Db);
queued = new QueuedMessage(sel);
wasQueued = SimpleResultBox<bool>.Create();
queued.SetSource(wasQueued, QueuedProcessor.Default);
_pending.Add(queued);
var server = multiplexer.SelectServer(message);
if (server != null && server.SupportsDatabases)
{
// people can do very naughty things in an EVAL
// including change the DB; change it back to what we
// think it should be!
var sel = PhysicalConnection.GetSelectDatabaseCommand(message.Db);
queued = new QueuedMessage(sel);
wasQueued = SimpleResultBox<bool>.Create();
queued.SetSource(wasQueued, QueuedProcessor.Default);
_pending.Add(queued);
}

break;
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/StackExchange.Redis.Tests/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,22 @@ public async Task CombineFireAndForgetAndRegularAsyncInTransaction()
Assert.Equal(30, count);
}

[Fact]
public async Task TransactionWithAdHocCommandsAndSelectDisabled()
{
using var conn = Create(disabledCommands: new string[] { "SELECT" });
RedisKey key = Me();
var db = conn.GetDatabase();
db.KeyDelete(key, CommandFlags.FireAndForget);
Assert.False(db.KeyExists(key));

var tran = db.CreateTransaction("state");
var a = tran.ExecuteAsync("SET", "foo", "bar");
Assert.True(await tran.ExecuteAsync());
var setting = db.StringGet("foo");
Assert.Equal("bar",setting);
}

#if VERBOSE
[Fact]
public async Task WatchAbort_StringEqual()
Expand Down

0 comments on commit e8b0006

Please sign in to comment.