Repository: microsoft/garnet
File: libs/server/Resp/AdminCommands.cs (C#)

Code before:
            {
                return AbortWithWrongNumberOfArguments(nameof(RespCommand.ROLE));
            }

            if (!storeWrapper.serverOptions.EnableCluster)
            {
                while (!RespWriteUtils.TryWriteArrayLength(3, ref dcurr, dend))
                    SendAndReset();

                while (!RespWriteUtils.TryWriteAsciiBulkString("master", ref dcurr, dend))
                    SendAndReset();

                while (!RespWriteUtils.TryWriteInt32(0, ref dcurr, dend))
                    SendAndReset();

                while (!RespWriteUtils.TryWriteEmptyArray(ref dcurr, dend))
                    SendAndReset();
            }
            else
            {
                if (storeWrapper.clusterProvider.IsPrimary())
                {
                    var (replication_offset, replicaInfo) = storeWrapper.clusterProvider.GetPrimaryInfo();

                    while (!RespWriteUtils.TryWriteArrayLength(3, ref dcurr, dend))
                        SendAndReset();

                    while (!RespWriteUtils.TryWriteAsciiBulkString("master", ref dcurr, dend))
                        SendAndReset();

                    while (!RespWriteUtils.TryWriteInt64(replication_offset, ref dcurr, dend))
                        SendAndReset();

                    while (!RespWriteUtils.TryWriteArrayLength(replicaInfo.Count, ref dcurr, dend))
                        SendAndReset();

                    foreach (var replice in replicaInfo)
                    {
                        while (!RespWriteUtils.TryWriteArrayLength(3, ref dcurr, dend))
                            SendAndReset();
                        while (!RespWriteUtils.TryWriteAsciiBulkString(replice.address, ref dcurr, dend))
                            SendAndReset();
                        while (!RespWriteUtils.TryWriteInt32(replice.port, ref dcurr, dend))
                            SendAndReset();
                        while (!RespWriteUtils.TryWriteInt64(replice.replication_offset, ref dcurr, dend))
                            SendAndReset();
                    }
                }
                else
                {
                    var role = storeWrapper.clusterProvider.GetReplicaInfo();

Review comment (bug):
Would be helpful to have a `DEBUG HELP` command for discoverability of these subcommands

Code after:

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.HELP))
            {
                var help = new List<string>()
                {
                    "DEBUG <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
                    "PANIC",
                    "\tCrash the server simulating a panic.",
                    "ERROR <string>",
                    "\tReturn a Redis protocol error with <string> as message. Useful for clients",
                    "\tunit tests to simulate Redis errors.",
                    "HELP",
                    "\tPrints this help"
                };

                while (!RespWriteUtils.TryWriteArrayLength(help.Count, ref dcurr, dend))
                    SendAndReset();

                foreach (var line in help)
                {
                    while (!RespWriteUtils.TryWriteSimpleString(line, ref dcurr, dend))
                        SendAndReset();
                }

                return true;
            }

            var error = string.Format(CmdStrings.GenericErrUnknownSubCommand, parseState.GetString(0), nameof(RespCommand.DEBUG));
            while (!RespWriteUtils.TryWriteError(error, ref dcurr, dend))
                SendAndReset();

            return true;
        }

        private bool NetworkROLE()
        {
            if (parseState.Count != 0)
            {
                return AbortWithWrongNumberOfArguments(nameof(RespCommand.ROLE));
            }

            if (!storeWrapper.serverOptions.EnableCluster)
            {
                while (!RespWriteUtils.TryWriteArrayLength(3, ref dcurr, dend))
                    SendAndReset();

                while (!RespWriteUtils.TryWriteAsciiBulkString("master", ref dcurr, dend))
                    SendAndReset();

                while (!RespWriteUtils.TryWriteInt32(0, ref dcurr, dend))
                    SendAndReset();