-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ROLE command #1551
Merged
Merged
Implement ROLE command #1551
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10691ad
api definition
55a8c0f
implement result processor for master role
b05af1f
implement replica and sentinel role parsing
9e9eb4f
add role to the sentinel allowed command list
0f09068
Merge remote-tracking branch 'upstream/main' into role-command
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ internal enum RedisCommand | |
RENAMENX, | ||
REPLICAOF, | ||
RESTORE, | ||
ROLE, | ||
RPOP, | ||
RPOPLPUSH, | ||
RPUSH, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StackExchange.Redis | ||
{ | ||
/// <summary> | ||
/// Result of the ROLE command. Values depend on the role: master, replica, or sentinel. | ||
/// </summary> | ||
/// <remarks>https://redis.io/commands/role</remarks> | ||
public abstract class Role | ||
{ | ||
/// <summary> | ||
/// One of "master", "slave" (aka replica), or "sentinel". | ||
/// </summary> | ||
public string Value { get; } | ||
|
||
private Role(string role) => Value = role; | ||
|
||
/// <summary> | ||
/// Result of the ROLE command for a master node. | ||
/// </summary> | ||
/// <remarks>https://redis.io/commands/role#master-output</remarks> | ||
public sealed class Master : Role | ||
{ | ||
/// <summary> | ||
/// The replication offset. To be consumed by replica nodes. | ||
/// </summary> | ||
public long ReplicationOffset { get; } | ||
|
||
/// <summary> | ||
/// Connected replica nodes. | ||
/// </summary> | ||
public ICollection<Replica> Replicas { get; } | ||
|
||
/// <summary> | ||
/// A connected replica node. | ||
/// </summary> | ||
public new readonly struct Replica | ||
{ | ||
/// <summary> | ||
/// The IP address of this replica node. | ||
/// </summary> | ||
public string Ip { get; } | ||
|
||
/// <summary> | ||
/// The port number of this replica node. | ||
/// </summary> | ||
public int Port { get; } | ||
|
||
/// <summary> | ||
/// The last replication offset acked by this replica node. | ||
/// </summary> | ||
public long ReplicationOffset { get; } | ||
|
||
internal Replica(string ip, int port, long offset) | ||
{ | ||
Ip = ip; | ||
Port = port; | ||
ReplicationOffset = offset; | ||
} | ||
} | ||
|
||
internal Master(long offset, ICollection<Replica> replicas) : base(RedisLiterals.master) | ||
{ | ||
ReplicationOffset = offset; | ||
Replicas = replicas; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Result of the ROLE command for a replica node. | ||
/// </summary> | ||
/// <remarks>https://redis.io/commands/role#output-of-the-command-on-replicas</remarks> | ||
public sealed class Replica : Role | ||
{ | ||
/// <summary> | ||
/// The IP address of the master node for this replica. | ||
/// </summary> | ||
public string MasterIp { get; } | ||
|
||
/// <summary> | ||
/// The port number of the master node for this replica. | ||
/// </summary> | ||
public int MasterPort { get; } | ||
|
||
/// <summary> | ||
/// This replica's replication state. | ||
/// </summary> | ||
public string State { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an enum, but returning the raw value seemed better for allowing the caller to do something useful with an unrecognized value. |
||
|
||
/// <summary> | ||
/// The last replication offset received by this replica. | ||
/// </summary> | ||
public long ReplicationOffset { get; } | ||
|
||
internal Replica(string role, string ip, int port, string state, long offset) : base(role) | ||
{ | ||
MasterIp = ip; | ||
MasterPort = port; | ||
State = state; | ||
ReplicationOffset = offset; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Result of the ROLE command for a sentinel node. | ||
/// </summary> | ||
/// <remarks>https://redis.io/commands/role#sentinel-output</remarks> | ||
public sealed class Sentinel : Role | ||
{ | ||
/// <summary> | ||
/// Master names monitored by this sentinel node. | ||
/// </summary> | ||
public ICollection<string> MonitoredMasters { get; } | ||
|
||
internal Sentinel(ICollection<string> masters) : base(RedisLiterals.sentinel) | ||
{ | ||
MonitoredMasters = masters; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// An unexpected result of the ROLE command. | ||
/// </summary> | ||
public sealed class Unknown : Role | ||
{ | ||
internal Unknown(string role) : base(role) { } | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the existing test helper and changed the usage to use the new code