using CommandLine; using StackExchange.Redis; using System; using RedisManager.Utils; namespace RedisManager.Commands { /// /// Command line options for the status command. /// Used to check the connectivity and response time of a Redis instance. /// [Verb("status", HelpText = "Check status of a Redis instance.")] public class StatusOptions { /// /// Gets or sets the name of the Redis instance to check. /// This must match a configured instance name in the configuration file. /// [Option('i', "instance", Required = true, HelpText = "Instance name.")] public string Instance { get; set; } } /// /// Static class containing the implementation for the status command. /// Provides functionality to check Redis instance connectivity and response time. /// public static class StatusCommand { /// /// Executes the status command to check Redis instance connectivity. /// Connects to the specified Redis instance and measures the ping response time. /// /// The status command options containing the instance name /// The RedisManager configuration containing instance details /// Exit code (0 for success, non-zero for failure) 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; } } }