Skip to content

Commit

Permalink
filter with builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
atakavci committed Jun 13, 2024
1 parent d53577c commit 49298bb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 74 deletions.
148 changes: 90 additions & 58 deletions src/StackExchange.Redis/APITypes/ClientKillFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,134 @@ public class ClientKillFilter
{
/// <summary>
/// Filter arguments for ClientKill
/// </summary>
/// <param name="id">The ID of the client to kill.</param>
/// <param name="clientType">The type of client.</param>
/// <param name="endpoint">The endpoint to kill.</param>
/// <param name="skipMe">Whether to skip the current connection.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(long? id, ClientType? clientType, EndPoint? endpoint, bool skipMe, int? maxAgeInSeconds)
/// </summary>
public ClientKillFilter() { }

/// <summary>
/// The ID of the client to kill.
/// </summary>
public long? Id
{
Id = id;
ClientType = clientType;
Endpoint = endpoint;
SkipMe = skipMe;
MaxAgeInSeconds = maxAgeInSeconds;
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// </summary>
/// <param name="id">The ID of the client to kill.</param>
/// <param name="clientType">The type of client.</param>
/// <param name="endpoint">The endpoint to kill.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(long? id, ClientType? clientType, EndPoint? endpoint, int? maxAgeInSeconds)
/// The type of client.
/// </summary>
public ClientType? ClientType
{
Id = id;
ClientType = clientType;
Endpoint = endpoint;
MaxAgeInSeconds = maxAgeInSeconds;
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// The authenticated ACL username,
/// </summary>
/// <param name="id">The ID of the client to kill.</param>
/// <param name="clientType">The type of client.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(long? id, ClientType? clientType, int? maxAgeInSeconds) { Id = id; ClientType = clientType; MaxAgeInSeconds = maxAgeInSeconds; }
/// <value></value>
public string? Username
{
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// The endpoint to kill.
/// </summary>
/// <param name="id">The ID of the client to kill.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(long? id, int? maxAgeInSeconds) { Id = id; MaxAgeInSeconds = maxAgeInSeconds; }
public EndPoint? Endpoint
{
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// The server endpoint to kill.
/// </summary>
/// <param name="clientType">The type of client.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(ClientType? clientType, int? maxAgeInSeconds) { ClientType = clientType; MaxAgeInSeconds = maxAgeInSeconds; }
public EndPoint? ServerEndpoint
{
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// Whether to skip the current connection.
/// </summary>
/// <param name="endpoint">The endpoint to kill.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(EndPoint? endpoint, int? maxAgeInSeconds) { Endpoint = endpoint; MaxAgeInSeconds = maxAgeInSeconds; }
public bool? SkipMe
{
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// Age of connection in seconds
/// </summary>
/// <param name="skipMe">Whether to skip the current connection.</param>
/// <param name="maxAgeInSeconds">Max age of connection in seconds, close older ones.</param>
public ClientKillFilter(bool skipMe, int? maxAgeInSeconds) { SkipMe = skipMe; MaxAgeInSeconds = maxAgeInSeconds; }
/// <value></value>
public long? MaxAgeInSeconds
{
get; private set;
}

/// <summary>
/// Filter arguments for ClientKill
/// Set id filter
/// </summary>
public ClientKillFilter() { }
/// <param name="id">Id of the client</param>
/// <returns></returns>
public ClientKillFilter WithId(long id)
{
Id = id; return this;
}

/// <summary>
/// The ID of the client to kill.
/// Set client type
/// </summary>
public long? Id { get; set; }
/// <param name="clientType">The type of the client</param>
/// <returns></returns>
public ClientKillFilter WithClientType(ClientType clientType)
{
ClientType = clientType; return this;
}

///
/// <summary>
/// The type of client.
/// Set username
/// </summary>
public ClientType? ClientType { get; set; }
/// <param name="username">Authenticated ACL username</param>
/// <returns></returns>
public ClientKillFilter WithUsername(string username)
{
Username = username; return this;
}

/// <summary>
/// The endpoint to kill.
/// Set endpoint
/// </summary>
public EndPoint? Endpoint { get; set; }
/// <param name="endpoint">The endpoint to kill.</param>
/// <returns></returns>
public ClientKillFilter WithEndpoint(EndPoint endpoint)
{
Endpoint = endpoint; return this;
}

/// <summary>
/// Whether to skip the current connection.
/// Set server endpoint
/// </summary>
public bool SkipMe { get; set; }
/// <param name="serverEndpoint">The server endpoint to kill.</param>
/// <returns></returns>
public ClientKillFilter WithServerEndpoint(EndPoint serverEndpoint)
{
ServerEndpoint = serverEndpoint; return this;
}

/// <summary>
/// Max age of connection in seconds, close older ones.
/// Set skipMe
/// </summary>
public long? MaxAgeInSeconds { get; set; }
/// <param name="skipMe">Whether to skip the current connection.</param>
/// <returns></returns>
public ClientKillFilter WithSkipMe(bool skipMe)
{
SkipMe = skipMe; return this;
}

/// <summary>
/// Set MaxAgeInSeconds
/// </summary>
/// <param name="maxAgeInSeconds">Age of connection in seconds</param>
/// <returns></returns>
public ClientKillFilter WithMaxAgeInSeconds(long maxAgeInSeconds)
{
MaxAgeInSeconds = maxAgeInSeconds; return this;
}
}

23 changes: 10 additions & 13 deletions src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,21 @@ StackExchange.Redis.ClientInfo.Raw.get -> string?
StackExchange.Redis.ClientInfo.SubscriptionCount.get -> int
StackExchange.Redis.ClientInfo.TransactionCommandLength.get -> int
StackExchange.Redis.ClientKillFilter
StackExchange.Redis.ClientKillFilter.ClientKillFilter(bool skipMe, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(long? id, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(long? id, StackExchange.Redis.ClientType? clientType, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(long? id, StackExchange.Redis.ClientType? clientType, System.Net.EndPoint? endpoint, bool skipMe, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(long? id, StackExchange.Redis.ClientType? clientType, System.Net.EndPoint? endpoint, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(StackExchange.Redis.ClientType? clientType, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter(System.Net.EndPoint? endpoint, int? maxAgeInSeconds) -> void
StackExchange.Redis.ClientKillFilter.ClientKillFilter() -> void
StackExchange.Redis.ClientKillFilter.ClientType.get -> StackExchange.Redis.ClientType?
StackExchange.Redis.ClientKillFilter.ClientType.set -> void
StackExchange.Redis.ClientKillFilter.Endpoint.get -> System.Net.EndPoint?
StackExchange.Redis.ClientKillFilter.Endpoint.set -> void
StackExchange.Redis.ClientKillFilter.Id.get -> long?
StackExchange.Redis.ClientKillFilter.Id.set -> void
StackExchange.Redis.ClientKillFilter.MaxAgeInSeconds.get -> long?
StackExchange.Redis.ClientKillFilter.MaxAgeInSeconds.set -> void
StackExchange.Redis.ClientKillFilter.SkipMe.get -> bool
StackExchange.Redis.ClientKillFilter.SkipMe.set -> void
StackExchange.Redis.ClientKillFilter.ServerEndpoint.get -> System.Net.EndPoint?
StackExchange.Redis.ClientKillFilter.SkipMe.get -> bool?
StackExchange.Redis.ClientKillFilter.Username.get -> string?
StackExchange.Redis.ClientKillFilter.WithClientType(StackExchange.Redis.ClientType clientType) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithEndpoint(System.Net.EndPoint! endpoint) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithId(long id) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithMaxAgeInSeconds(long maxAgeInSeconds) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithServerEndpoint(System.Net.EndPoint! serverEndpoint) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithSkipMe(bool skipMe) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientKillFilter.WithUsername(string! username) -> StackExchange.Redis.ClientKillFilter!
StackExchange.Redis.ClientType
StackExchange.Redis.ClientType.Normal = 0 -> StackExchange.Redis.ClientType
StackExchange.Redis.ClientType.PubSub = 2 -> StackExchange.Redis.ClientType
Expand Down
4 changes: 2 additions & 2 deletions src/StackExchange.Redis/RedisServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Task<long> ClientKillAsync(ClientKillFilter filter, CommandFlags flags =
return ExecuteAsync(msg, ResultProcessor.Int64);
}

private Message GetClientKillMessage(EndPoint? endpoint, long? id, ClientType? clientType, bool skipMe, long? maxAgeInSeconds, CommandFlags flags)
private Message GetClientKillMessage(EndPoint? endpoint, long? id, ClientType? clientType, bool? skipMe, long? maxAgeInSeconds, CommandFlags flags)
{
var parts = new List<RedisValue>(9)
{
Expand Down Expand Up @@ -121,7 +121,7 @@ private Message GetClientKillMessage(EndPoint? endpoint, long? id, ClientType? c
parts.Add(RedisLiterals.ADDR);
parts.Add((RedisValue)Format.ToString(endpoint));
}
if (!skipMe)
if (skipMe != null)
{
parts.Add(RedisLiterals.SKIPME);
parts.Add(RedisLiterals.no);
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/ClientKillTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void ClientKillWithMaxAge()

using var conn = Create(allowAdmin: true, shared: false, backlogPolicy: BacklogPolicy.FailFast);
var server = conn.GetServer(conn.GetEndPoints()[0]);
var filter = new ClientKillFilter() { Id = id.AsInt64(), MaxAgeInSeconds = 1, SkipMe = true };
var filter = new ClientKillFilter().WithId(id.AsInt64()).WithMaxAgeInSeconds(1).WithSkipMe(true);
long result = server.ClientKill(filter, CommandFlags.DemandMaster);
Assert.Equal(1, result);
}
Expand Down

0 comments on commit 49298bb

Please sign in to comment.