46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
using CommandLine;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using RedisManager.Utils;
|
|
|
|
namespace RedisManager.Commands
|
|
{
|
|
/// <summary>
|
|
/// Command line options for the status command.
|
|
/// Used to check the connectivity and response time of a Redis instance.
|
|
/// </summary>
|
|
[Verb("status", HelpText = "Check status of a Redis instance.")]
|
|
public class StatusOptions
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the name of the Redis instance to check.
|
|
/// This must match a configured instance name in the configuration file.
|
|
/// </summary>
|
|
[Option('i', "instance", Required = true, HelpText = "Instance name.")]
|
|
public string Instance { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Static class containing the implementation for the status command.
|
|
/// Provides functionality to check Redis instance connectivity and response time.
|
|
/// </summary>
|
|
public static class StatusCommand
|
|
{
|
|
/// <summary>
|
|
/// Executes the status command to check Redis instance connectivity.
|
|
/// Connects to the specified Redis instance and measures the ping response time.
|
|
/// </summary>
|
|
/// <param name="opts">The status command options containing the instance name</param>
|
|
/// <param name="config">The RedisManager configuration containing instance details</param>
|
|
/// <returns>Exit code (0 for success, non-zero for failure)</returns>
|
|
public static int RunStatus(StatusOptions opts, Config config)
|
|
{
|
|
var instance = RedisUtils.GetInstance(config, opts.Instance);
|
|
using var redis = RedisUtils.ConnectRedis(instance);
|
|
var db = redis.GetDatabase();
|
|
var pong = db.Ping();
|
|
Console.WriteLine(Output.Green($"PONG: {pong.TotalMilliseconds}ms"));
|
|
return 0;
|
|
}
|
|
}
|
|
} |