Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions StackExchange.Redis.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=keepttl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lpush/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lrange/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=psubscribe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pubsub/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rpush/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=spublish/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sscan/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ssubscribe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vectorset/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=xinfo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=xpending/@EntryIndexedValue">True</s:Boolean>
Expand Down
64 changes: 64 additions & 0 deletions src/StackExchange.Redis/ChannelMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace StackExchange.Redis;

/// <summary>
/// Represents a message that is broadcast via publish/subscribe.
/// </summary>
public readonly struct ChannelMessage
{
// this is *smaller* than storing a RedisChannel for the subscribed channel
private readonly ChannelMessageQueue _queue;

/// <summary>
/// The Channel:Message string representation.
/// </summary>
public override string ToString() => ((string?)Channel) + ":" + ((string?)Message);

/// <inheritdoc/>
public override int GetHashCode() => Channel.GetHashCode() ^ Message.GetHashCode();

/// <inheritdoc/>
public override bool Equals(object? obj) => obj is ChannelMessage cm
&& cm.Channel == Channel && cm.Message == Message;

internal ChannelMessage(ChannelMessageQueue queue, in RedisChannel channel, in RedisValue value)
{
_queue = queue;
_channel = channel;
_message = value;
}

/// <summary>
/// The channel that the subscription was created from.
/// </summary>
public RedisChannel SubscriptionChannel => _queue.Channel;

private readonly RedisChannel _channel;

/// <summary>
/// The channel that the message was broadcast to.
/// </summary>
public RedisChannel Channel => _channel;

private readonly RedisValue _message;

/// <summary>
/// The value that was broadcast.
/// </summary>
public RedisValue Message => _message;

/// <summary>
/// Checks if 2 messages are .Equal().
/// </summary>
public static bool operator ==(ChannelMessage left, ChannelMessage right) => left.Equals(right);

/// <summary>
/// Checks if 2 messages are not .Equal().
/// </summary>
public static bool operator !=(ChannelMessage left, ChannelMessage right) => !left.Equals(right);

/// <summary>
/// If the channel is either a keyspace or keyevent notification, resolve the key and event type.
/// </summary>
public bool TryParseKeyNotification(out KeyNotification notification)
=> KeyNotification.TryParse(in _channel, in _message, out notification);
}
Loading
Loading