33using System . Collections . Generic ;
44using System . Text . RegularExpressions ;
55using System . Threading ;
6+ using RESPite . Messages ;
67
78namespace StackExchange . Redis . Server ;
89
@@ -182,7 +183,7 @@ public int Publish(in RedisChannel channel, in RedisValue value)
182183 // we can do simple and sharded equality lookups directly
183184 if ( ( simpleCount + shardedCount ) != 0 && subs . TryGetValue ( channel , out _ ) )
184185 {
185- var msg = TypedRedisValue . Rent ( 3 , out var span , ResultType . Push ) ;
186+ var msg = TypedRedisValue . Rent ( 3 , out var span , PushKind ) ;
186187 span [ 0 ] = TypedRedisValue . BulkString ( channel . IsSharded ? "smessage" : "message" ) ;
187188 span [ 1 ] = TypedRedisValue . BulkString ( channel ) ;
188189 span [ 2 ] = TypedRedisValue . BulkString ( value ) ;
@@ -198,7 +199,7 @@ public int Publish(in RedisChannel channel, in RedisValue value)
198199 {
199200 if ( pair . Key . IsPattern && pair . Value is { } glob && glob . IsMatch ( channelName ) )
200201 {
201- var msg = TypedRedisValue . Rent ( 4 , out var span , ResultType . Push ) ;
202+ var msg = TypedRedisValue . Rent ( 4 , out var span , PushKind ) ;
202203 span [ 0 ] = TypedRedisValue . BulkString ( "pmessage" ) ;
203204 span [ 1 ] = TypedRedisValue . BulkString ( pair . Key ) ;
204205 span [ 2 ] = TypedRedisValue . BulkString ( channel ) ;
@@ -213,11 +214,15 @@ public int Publish(in RedisChannel channel, in RedisValue value)
213214 return count ;
214215 }
215216
216- private void SendMessage ( string kind , RedisChannel channel , int count )
217+ public bool IsResp2 => Protocol is RedisProtocol . Resp2 ;
218+
219+ public RespPrefix PushKind => IsResp2 ? RespPrefix . Array : RespPrefix . Push ;
220+
221+ private void SendSubUnsubMessage ( string kind , RedisChannel channel , int count )
217222 {
218223 if ( Node is { } node )
219224 {
220- var reply = TypedRedisValue . Rent ( 3 , out var span , ResultType . Push ) ;
225+ var reply = TypedRedisValue . Rent ( 3 , out var span , PushKind ) ;
221226 span [ 0 ] = TypedRedisValue . BulkString ( kind ) ;
222227 span [ 1 ] = TypedRedisValue . BulkString ( ( byte [ ] ) channel ) ;
223228 span [ 2 ] = TypedRedisValue . Integer ( count ) ;
@@ -239,7 +244,7 @@ internal void Subscribe(RedisChannel channel)
239244 : channel . IsPattern ? ++ patternCount
240245 : ++ simpleCount ;
241246 }
242- SendMessage (
247+ SendSubUnsubMessage (
243248 channel . IsSharded ? "ssubscribe"
244249 : channel . IsPattern ? "psubscribe"
245250 : "subscribe" ,
@@ -273,7 +278,7 @@ internal void Unsubscribe(RedisChannel channel)
273278 : channel . IsPattern ? -- patternCount
274279 : -- simpleCount ;
275280 }
276- SendMessage (
281+ SendSubUnsubMessage (
277282 channel . IsSharded ? "sunsubscribe"
278283 : channel . IsPattern ? "punsubscribe"
279284 : "unsubscribe" ,
@@ -332,7 +337,7 @@ internal void UnsubscribeAll(RedisCommand cmd)
332337 }
333338 foreach ( var key in remove . AsSpan ( 0 , count ) )
334339 {
335- SendMessage ( msg , key , 0 ) ;
340+ SendSubUnsubMessage ( msg , key , 0 ) ;
336341 }
337342 ArrayPool < RedisChannel > . Shared . Return ( remove ) ;
338343 }
0 commit comments