Skip to content

Commit e8b0006

Browse files
authored
Honor select disposition in transactions (#2322)
* honor select disposition in transactions * rearranging if/switch * using server instead of multiplxer * release notes
1 parent 0233585 commit e8b0006

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Current package versions:
7878
- 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))
7979
- Adds: `IConnectionMultiplexer.ServerMaintenanceEvent` (was on `ConnectionMultiplexer` but not the interface) ([#2306 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2306))
8080
- 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))
81-
81+
- 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)
8282

8383
## 2.6.80
8484

src/StackExchange.Redis/RedisTransaction.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,24 @@ private void QueueMessage(Message message)
116116
lock (SyncLock)
117117
{
118118
(_pending ??= new List<QueuedMessage>()).Add(queued);
119-
120119
switch (message.Command)
121120
{
122121
case RedisCommand.UNKNOWN:
123122
case RedisCommand.EVAL:
124123
case RedisCommand.EVALSHA:
125-
// people can do very naughty things in an EVAL
126-
// including change the DB; change it back to what we
127-
// think it should be!
128-
var sel = PhysicalConnection.GetSelectDatabaseCommand(message.Db);
129-
queued = new QueuedMessage(sel);
130-
wasQueued = SimpleResultBox<bool>.Create();
131-
queued.SetSource(wasQueued, QueuedProcessor.Default);
132-
_pending.Add(queued);
124+
var server = multiplexer.SelectServer(message);
125+
if (server != null && server.SupportsDatabases)
126+
{
127+
// people can do very naughty things in an EVAL
128+
// including change the DB; change it back to what we
129+
// think it should be!
130+
var sel = PhysicalConnection.GetSelectDatabaseCommand(message.Db);
131+
queued = new QueuedMessage(sel);
132+
wasQueued = SimpleResultBox<bool>.Create();
133+
queued.SetSource(wasQueued, QueuedProcessor.Default);
134+
_pending.Add(queued);
135+
}
136+
133137
break;
134138
}
135139
}

tests/StackExchange.Redis.Tests/TransactionTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,22 @@ public async Task CombineFireAndForgetAndRegularAsyncInTransaction()
12191219
Assert.Equal(30, count);
12201220
}
12211221

1222+
[Fact]
1223+
public async Task TransactionWithAdHocCommandsAndSelectDisabled()
1224+
{
1225+
using var conn = Create(disabledCommands: new string[] { "SELECT" });
1226+
RedisKey key = Me();
1227+
var db = conn.GetDatabase();
1228+
db.KeyDelete(key, CommandFlags.FireAndForget);
1229+
Assert.False(db.KeyExists(key));
1230+
1231+
var tran = db.CreateTransaction("state");
1232+
var a = tran.ExecuteAsync("SET", "foo", "bar");
1233+
Assert.True(await tran.ExecuteAsync());
1234+
var setting = db.StringGet("foo");
1235+
Assert.Equal("bar",setting);
1236+
}
1237+
12221238
#if VERBOSE
12231239
[Fact]
12241240
public async Task WatchAbort_StringEqual()

0 commit comments

Comments
 (0)