Skip to content

Commit 8e9fe07

Browse files
authored
Merge branch 'main' into marc/get-server-keyed
2 parents ca35ea8 + b03e5f7 commit 8e9fe07

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Current package versions:
1414
- Add support for XPENDING Idle time filter ([#2822 by david-brink-talogy](https://github.com/StackExchange/StackExchange.Redis/pull/2822))
1515
- Improve `double` formatting performance on net8+ ([#2928 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2928))
1616
- Add `GetServer(RedisKey, ...)` API ([#2936 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2936))
17+
- Fix error constructing `StreamAdd` message ([#2941 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2941))
1718

1819
## 2.8.58
1920

src/StackExchange.Redis/RedisDatabase.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,13 +4598,12 @@ private Message GetStreamAddMessage(RedisKey key, RedisValue entryId, long? maxL
45984598
throw new ArgumentOutOfRangeException(nameof(maxLength), "maxLength must be greater than 0.");
45994599
}
46004600

4601-
var includeMaxLen = maxLength.HasValue ? 2 : 0;
4602-
var includeApproxLen = maxLength.HasValue && useApproximateMaxLength ? 1 : 0;
4603-
46044601
var totalLength = (streamPairs.Length * 2) // Room for the name/value pairs
4605-
+ 1 // The stream entry ID
4606-
+ includeMaxLen // 2 or 0 (MAXLEN keyword & the count)
4607-
+ includeApproxLen; // 1 or 0
4602+
+ 1 // The stream entry ID
4603+
+ (maxLength.HasValue ? 2 : 0) // MAXLEN N
4604+
+ (maxLength.HasValue && useApproximateMaxLength ? 1 : 0) // ~
4605+
+ (mode == StreamTrimMode.KeepReferences ? 0 : 1) // relevant trim-mode keyword
4606+
+ (limit.HasValue ? 2 : 0); // LIMIT N
46084607

46094608
var values = new RedisValue[totalLength];
46104609

tests/RedisConfigs/.docker/Redis/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM redis:7.4.2
1+
FROM redis:8.2.0
22

33
COPY --from=configs ./Basic /data/Basic/
44
COPY --from=configs ./Failover /data/Failover/

tests/StackExchange.Redis.Tests/AbortOnConnectFailTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ public async Task DisconnectAndNoReconnectThrowsConnectionExceptionAsync()
8181
}
8282

8383
private ConnectionMultiplexer GetFailFastConn() =>
84-
ConnectionMultiplexer.Connect(GetOptions(BacklogPolicy.FailFast, 400).Apply(o => o.EndPoints.Add($"doesnot.exist.{Guid.NewGuid():N}:6379")), Writer);
84+
ConnectionMultiplexer.Connect(GetOptions(BacklogPolicy.FailFast, duration: 400, connectTimeout: 500).Apply(o => o.EndPoints.Add($"doesnot.exist.{Guid.NewGuid():N}:6379")), Writer);
8585

8686
private ConnectionMultiplexer GetWorkingBacklogConn() =>
87-
ConnectionMultiplexer.Connect(GetOptions(BacklogPolicy.Default, 1000).Apply(o => o.EndPoints.Add(GetConfiguration())), Writer);
87+
ConnectionMultiplexer.Connect(GetOptions(BacklogPolicy.Default).Apply(o => o.EndPoints.Add(GetConfiguration())), Writer);
8888

89-
private static ConfigurationOptions GetOptions(BacklogPolicy policy, int duration) => new ConfigurationOptions()
89+
private static ConfigurationOptions GetOptions(BacklogPolicy policy, int duration = 1000, int connectTimeout = 2000) => new ConfigurationOptions()
9090
{
9191
AbortOnConnectFail = false,
9292
BacklogPolicy = policy,
93-
ConnectTimeout = 500,
93+
ConnectTimeout = connectTimeout,
9494
SyncTimeout = duration,
9595
KeepAlive = duration,
9696
AllowAdmin = true,

tests/StackExchange.Redis.Tests/KeyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public async Task KeyEncoding()
182182
db.KeyDelete(key, CommandFlags.FireAndForget);
183183
db.StringSet(key, "new value", flags: CommandFlags.FireAndForget);
184184

185-
Assert.True(db.KeyEncoding(key) is "embstr" or "raw");
185+
Assert.True(db.KeyEncoding(key) is "embstr" or "raw"); // server-version dependent
186186
Assert.True(await db.KeyEncodingAsync(key) is "embstr" or "raw");
187187

188188
db.KeyDelete(key, CommandFlags.FireAndForget);

tests/StackExchange.Redis.Tests/StreamTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,28 @@ public async Task AddWithApproxCount(StreamTrimMode mode)
21552155
db.StreamAdd(key, "field", "value", maxLength: 10, useApproximateMaxLength: true, trimMode: mode, flags: CommandFlags.None);
21562156
}
21572157

2158+
[Theory]
2159+
[InlineData(StreamTrimMode.KeepReferences, 1)]
2160+
[InlineData(StreamTrimMode.DeleteReferences, 1)]
2161+
[InlineData(StreamTrimMode.Acknowledged, 1)]
2162+
[InlineData(StreamTrimMode.KeepReferences, 2)]
2163+
[InlineData(StreamTrimMode.DeleteReferences, 2)]
2164+
[InlineData(StreamTrimMode.Acknowledged, 2)]
2165+
public async Task AddWithMultipleApproxCount(StreamTrimMode mode, int count)
2166+
{
2167+
await using var conn = Create(require: ForMode(mode));
2168+
2169+
var db = conn.GetDatabase();
2170+
var key = Me() + ":" + mode;
2171+
2172+
var pairs = new NameValueEntry[count];
2173+
for (var i = 0; i < count; i++)
2174+
{
2175+
pairs[i] = new NameValueEntry($"field{i}", $"value{i}");
2176+
}
2177+
db.StreamAdd(key, maxLength: 10, useApproximateMaxLength: true, trimMode: mode, flags: CommandFlags.None, streamPairs: pairs);
2178+
}
2179+
21582180
[Fact]
21592181
public async Task StreamReadGroupWithNoAckShowsNoPendingMessages()
21602182
{

0 commit comments

Comments
 (0)