Skip to content

Commit b03e5f7

Browse files
authored
fix error in XADD arg-count calculation (#2941)
* fix error in XADD arg-count calculation fix #2940 * release notes * fix CI fail - key can now be embstr or raw * CI update to redis 8.2.0
1 parent 8fffdff commit b03e5f7

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Current package versions:
1313
- Add `Condition.SortedSet[Not]ContainsStarting` condition for transactions ([#2638 by ArnoKoll](https://github.com/StackExchange/StackExchange.Redis/pull/2638))
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))
16+
- Fix error constructing `StreamAdd` message ([#2941 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2941))
1617

1718
## 2.8.58
1819

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/KeyTests.cs

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

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

188188
db.KeyDelete(key, CommandFlags.FireAndForget);
189189
db.ListLeftPush(key, "new value", flags: 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)