Skip to content

Commit 77a159c

Browse files
authored
for pub/sub, treat length-one arrays comparably to simple values (#2118)
* fix #2117 for pub/sub, treak length-one arrays comparably to simple values * update release notes * actually check whether we're meant to be allowing arrays
1 parent d3e26c4 commit 77a159c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Adds: Support for `OBJECT FREQ` with `.KeyFrequency()`/`.KeyFrequencyAsync()` ([#2105 by Avital-Fine](https://github.com/StackExchange/StackExchange.Redis/pull/2105))
3030
- Performance: Avoids allocations when computing cluster hash slots or testing key equality ([#2110 by Marc Gravell](https://github.com/StackExchange/StackExchange.Redis/pull/2110))
3131
- Adds: Support for `SORT_RO` with `.Sort()`/`.SortAsync()` ([#2111 by slorello89](https://github.com/StackExchange/StackExchange.Redis/pull/2111))
32+
- Adds: Support for pub/sub payloads that are unary arrays ([#2118 by Marc Gravell](https://github.com/StackExchange/StackExchange.Redis/pull/2118))
3233

3334
## 2.5.61
3435

src/StackExchange.Redis/PhysicalConnection.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,10 @@ private void MatchResult(in RawResult result)
14981498
// invoke the handlers
14991499
var channel = items[1].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Literal);
15001500
Trace("MESSAGE: " + channel);
1501-
if (!channel.IsNull)
1501+
if (!channel.IsNull && TryGetPubSubPayload(items[2], out var payload))
15021502
{
15031503
_readStatus = ReadStatus.InvokePubSub;
1504-
muxer.OnMessage(channel, channel, items[2].AsRedisValue());
1504+
muxer.OnMessage(channel, channel, payload);
15051505
}
15061506
return; // AND STOP PROCESSING!
15071507
}
@@ -1511,11 +1511,11 @@ private void MatchResult(in RawResult result)
15111511

15121512
var channel = items[2].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Literal);
15131513
Trace("PMESSAGE: " + channel);
1514-
if (!channel.IsNull)
1514+
if (!channel.IsNull && TryGetPubSubPayload(items[3], out var payload))
15151515
{
15161516
var sub = items[1].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Pattern);
15171517
_readStatus = ReadStatus.InvokePubSub;
1518-
muxer.OnMessage(sub, channel, items[3].AsRedisValue());
1518+
muxer.OnMessage(sub, channel, payload);
15191519
}
15201520
return; // AND STOP PROCESSING!
15211521
}
@@ -1551,6 +1551,27 @@ private void MatchResult(in RawResult result)
15511551
}
15521552
_readStatus = ReadStatus.MatchResultComplete;
15531553
_activeMessage = null;
1554+
1555+
static bool TryGetPubSubPayload(in RawResult value, out RedisValue parsed, bool allowArraySingleton = true)
1556+
{
1557+
if (value.IsNull)
1558+
{
1559+
parsed = RedisValue.Null;
1560+
return true;
1561+
}
1562+
switch (value.Type)
1563+
{
1564+
case ResultType.Integer:
1565+
case ResultType.SimpleString:
1566+
case ResultType.BulkString:
1567+
parsed = value.AsRedisValue();
1568+
return true;
1569+
case ResultType.MultiBulk when allowArraySingleton && value.ItemsCount == 1:
1570+
return TryGetPubSubPayload(in value[0], out parsed, allowArraySingleton: false);
1571+
}
1572+
parsed = default;
1573+
return false;
1574+
}
15541575
}
15551576

15561577
private volatile Message? _activeMessage;

0 commit comments

Comments
 (0)