@@ -10,6 +10,7 @@ namespace StackExchange.Redis
1010 {
1111 internal readonly byte [ ] ? Value ;
1212 internal readonly bool _isPatternBased ;
13+ internal readonly bool _isSharded ;
1314
1415 /// <summary>
1516 /// Indicates whether the channel-name is either null or a zero-length value.
@@ -21,6 +22,11 @@ namespace StackExchange.Redis
2122 /// </summary>
2223 public bool IsPattern => _isPatternBased ;
2324
25+ /// <summary>
26+ /// Indicates whether this channel represents a shard channel (see <c>SSUBSCRIBE</c>)
27+ /// </summary>
28+ public bool IsSharded => _isSharded ;
29+
2430 internal bool IsNull => Value == null ;
2531
2632 /// <summary>
@@ -59,7 +65,7 @@ public static bool UseImplicitAutoPattern
5965 /// </summary>
6066 /// <param name="value">The name of the channel to create.</param>
6167 /// <param name="mode">The mode for name matching.</param>
62- public RedisChannel ( byte [ ] ? value , PatternMode mode ) : this ( value , DeterminePatternBased ( value , mode ) ) { }
68+ public RedisChannel ( byte [ ] ? value , PatternMode mode ) : this ( value , DeterminePatternBased ( value , mode ) , false ) { }
6369
6470 /// <summary>
6571 /// Create a new redis channel from a string, explicitly controlling the pattern mode.
@@ -68,10 +74,25 @@ public RedisChannel(byte[]? value, PatternMode mode) : this(value, DeterminePatt
6874 /// <param name="mode">The mode for name matching.</param>
6975 public RedisChannel ( string value , PatternMode mode ) : this ( value == null ? null : Encoding . UTF8 . GetBytes ( value ) , mode ) { }
7076
71- private RedisChannel ( byte [ ] ? value , bool isPatternBased )
77+ /// <summary>
78+ /// Create a new redis channel from a buffer, explicitly controlling the sharding mode.
79+ /// </summary>
80+ /// <param name="value">The name of the channel to create.</param>
81+ /// <param name="isSharded">Whether the channel is sharded.</param>
82+ public RedisChannel ( byte [ ] ? value , bool isSharded ) : this ( value , false , isSharded ) { }
83+
84+ /// <summary>
85+ /// Create a new redis channel from a string, explicitly controlling the sharding mode.
86+ /// </summary>
87+ /// <param name="value">The string name of the channel to create.</param>
88+ /// <param name="isSharded">Whether the channel is sharded.</param>
89+ public RedisChannel ( string value , bool isSharded ) : this ( value == null ? null : Encoding . UTF8 . GetBytes ( value ) , isSharded ) { }
90+
91+ private RedisChannel ( byte [ ] ? value , bool isPatternBased , bool isSharded )
7292 {
7393 Value = value ;
7494 _isPatternBased = isPatternBased ;
95+ _isSharded = isSharded ;
7596 }
7697
7798 private static bool DeterminePatternBased ( byte [ ] ? value , PatternMode mode ) => mode switch
@@ -123,7 +144,7 @@ private RedisChannel(byte[]? value, bool isPatternBased)
123144 /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
124145 /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
125146 public static bool operator == ( RedisChannel x , RedisChannel y ) =>
126- x . _isPatternBased == y . _isPatternBased && RedisValue . Equals ( x . Value , y . Value ) ;
147+ x . _isPatternBased == y . _isPatternBased && RedisValue . Equals ( x . Value , y . Value ) && x . _isSharded == y . _isSharded ;
127148
128149 /// <summary>
129150 /// Indicate whether two channel names are equal.
@@ -171,10 +192,10 @@ private RedisChannel(byte[]? value, bool isPatternBased)
171192 /// Indicate whether two channel names are equal.
172193 /// </summary>
173194 /// <param name="other">The <see cref="RedisChannel"/> to compare to.</param>
174- public bool Equals ( RedisChannel other ) => _isPatternBased == other . _isPatternBased && RedisValue . Equals ( Value , other . Value ) ;
195+ public bool Equals ( RedisChannel other ) => _isPatternBased == other . _isPatternBased && RedisValue . Equals ( Value , other . Value ) && _isSharded == other . _isSharded ;
175196
176197 /// <inheritdoc/>
177- public override int GetHashCode ( ) => RedisValue . GetHashCode ( Value ) + ( _isPatternBased ? 1 : 0 ) ;
198+ public override int GetHashCode ( ) => RedisValue . GetHashCode ( Value ) + ( _isPatternBased ? 1 : 0 ) + ( _isSharded ? 2 : 0 ) ;
178199
179200 /// <summary>
180201 /// Obtains a string representation of the channel name.
@@ -286,4 +307,4 @@ public static implicit operator RedisChannel(byte[]? key)
286307 private RedisChannel ( byte [ ] ? value ) => throw new NotSupportedException ( ) ;
287308#endif
288309 }
289- }
310+ }
0 commit comments