Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions libs/common/RespMemoryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void WriteAsciiDirect(ReadOnlySpan<char> span)
}

/// <summary>
/// Writes an array str to memory.
/// Writes an array item to memory.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteArrayItem(long item)
Expand Down Expand Up @@ -192,7 +192,6 @@ public void WriteEmptyMap()
/// Write simple error to memory.
/// </summary>
/// <param name="errorString">An ASCII encoded error string. The string mustn't contain a CR (\r) or LF (\n) bytes.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteError(scoped ReadOnlySpan<byte> errorString)
{
while (!RespWriteUtils.TryWriteError(errorString, ref curr, end))
Expand Down Expand Up @@ -227,6 +226,18 @@ public void TryWriteFalse()
}
}

/// <summary>
/// Write Help output
/// </summary>
public void WriteHelp(params string[] Help)
{
WriteArrayLength(Help.Length);
foreach (var help in Help)
{
WriteSimpleString(help);
}
}

/// <summary>
/// Write integer to memory.
/// </summary>
Expand Down
56 changes: 56 additions & 0 deletions libs/resources/RespCommandsDocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
}
]
},
{
"Command": "ACL_HELP",
"Name": "ACL|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "ACL_LIST",
"Name": "ACL|LIST",
Expand Down Expand Up @@ -944,6 +951,13 @@
"Group": "Connection",
"Complexity": "O(1)"
},
{
"Command": "CLIENT_HELP",
"Name": "CLIENT|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "CLIENT_ID",
"Name": "CLIENT|ID",
Expand Down Expand Up @@ -1722,6 +1736,13 @@
}
]
},
{
"Command": "COMMAND_HELP",
"Name": "COMMAND|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "COMMAND_INFO",
"Name": "COMMAND|INFO",
Expand Down Expand Up @@ -1779,6 +1800,13 @@
}
]
},
{
"Command": "CONFIG_HELP",
"Name": "CONFIG|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "CONFIG_REWRITE",
"Name": "CONFIG|REWRITE",
Expand Down Expand Up @@ -5335,6 +5363,13 @@
"Group": "Server",
"Complexity": "Depends on subcommand.",
"SubCommands": [
{
"Command": "MEMORY_HELP",
"Name": "MEMORY|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "MEMORY_USAGE",
"Name": "MEMORY|USAGE",
Expand Down Expand Up @@ -5499,6 +5534,13 @@
"Group": "Server",
"Complexity": "Depends on subcommand.",
"SubCommands": [
{
"Command": "MODULE_HELP",
"Name": "MODULE|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "MODULE_LOADCS",
"Name": "MODULE|LOADCS",
Expand Down Expand Up @@ -5931,6 +5973,13 @@
}
]
},
{
"Command": "PUBSUB_HELP",
"Name": "PUBSUB|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "PUBSUB_NUMPAT",
"Name": "PUBSUB|NUMPAT",
Expand Down Expand Up @@ -6590,6 +6639,13 @@
}
]
},
{
"Command": "SCRIPT_HELP",
"Name": "SCRIPT|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "SCRIPT_LOAD",
"Name": "SCRIPT|LOAD",
Expand Down
60 changes: 58 additions & 2 deletions libs/resources/RespCommandsInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@
"Arity": -2,
"Flags": "Loading, NoScript, Stale",
"AclCategories": "Slow"
},
{
"Command": "ACL_HELP",
"Name": "ACL|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
}
]
},
Expand Down Expand Up @@ -524,6 +531,13 @@
"Flags": "Loading, NoScript, Stale",
"AclCategories": "Connection, Slow"
},
{
"Command": "CLIENT_HELP",
"Name": "CLIENT|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "CLIENT_ID",
"Name": "CLIENT|ID",
Expand Down Expand Up @@ -1018,6 +1032,13 @@
"Flags": "Loading, Stale",
"AclCategories": "Connection, Slow"
},
{
"Command": "COMMAND_HELP",
"Name": "COMMAND|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "COMMAND_INFO",
"Name": "COMMAND|INFO",
Expand Down Expand Up @@ -1053,6 +1074,13 @@
"Flags": "Admin, Loading, NoScript, Stale",
"AclCategories": "Admin, Dangerous, Slow"
},
{
"Command": "CONFIG_HELP",
"Name": "CONFIG|HELP",
"Arity": 2,
"Flags": "Admin, Loading, NoScript, Stale",
"AclCategories": "Slow, Garnet"
},
{
"Command": "CONFIG_REWRITE",
"Name": "CONFIG|REWRITE",
Expand Down Expand Up @@ -2781,8 +2809,8 @@
"Command": "LATENCY_HELP",
"Name": "LATENCY|HELP",
"Arity": 2,
"Flags": "Admin, Loading, NoScript, Stale",
"AclCategories": "Slow, Garnet"
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "LATENCY_HISTOGRAM",
Expand Down Expand Up @@ -3175,6 +3203,13 @@
"Arity": -2,
"AclCategories": "Slow",
"SubCommands": [
{
"Command": "MEMORY_HELP",
"Name": "MEMORY|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "MEMORY_USAGE",
"Name": "MEMORY|USAGE",
Expand Down Expand Up @@ -3285,6 +3320,13 @@
"Arity": -3,
"Flags": "Admin, NoAsyncLoading, NoScript",
"AclCategories": "Admin, Dangerous, Slow"
},
{
"Command": "MODULE_HELP",
"Name": "MODULE|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
}
]
},
Expand Down Expand Up @@ -3636,6 +3678,13 @@
"Flags": "Loading, PubSub, Stale",
"AclCategories": "PubSub, Slow"
},
{
"Command": "PUBSUB_HELP",
"Name": "PUBSUB|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "PUBSUB_NUMPAT",
"Name": "PUBSUB|NUMPAT",
Expand Down Expand Up @@ -4035,6 +4084,13 @@
"response_policy:all_succeeded"
]
},
{
"Command": "SCRIPT_HELP",
"Name": "SCRIPT|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "SCRIPT_LOAD",
"Name": "SCRIPT|LOAD",
Expand Down
28 changes: 28 additions & 0 deletions libs/server/Lua/LuaCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,34 @@ private bool NetworkScriptFlush()
return true;
}


/// <summary>
/// SCRIPT HELP
/// </summary>
/// <returns></returns>
private bool NetworkScriptHelp()
{
if (parseState.Count != 0)
{
return AbortWithWrongNumberOfArguments("script|help");
}

WriteHelp(
"SCRIPT <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a RespCommandsHelp.json resource file that gets loaded on an as-needed basis, similarly to Docs/Info. This file can also get populated automagically by the CommandInfoUpdater tool.

"EXISTS <sha1> [<sha1> ...]",
"\tReturn information about the existence of the scripts in the script cache.",
"FLUSH [ASYNC|SYNC]",
"\tFlush the Lua scripts cache. Very dangerous on replicas. Valid modes are:",
"\t* ASYNC: Asynchronously flush the scripts cache.",
"\t* SYNC: Synchronously flush the scripts cache.",
"LOAD <script>",
"\tLoad a script into the scripts cache without executing it.",
"HELP",
"\tPrint this help.");

return true;
}

/// <summary>
/// SCRIPT|LOAD
/// </summary>
Expand Down
13 changes: 3 additions & 10 deletions libs/server/Metrics/Latency/RespLatencyCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ private bool NetworkLatencyHelp()
// No additional arguments
if (parseState.Count != 0)
{
return AbortWithErrorMessage($"ERR Unknown subcommand or wrong number of arguments for LATENCY HELP.");
return AbortWithWrongNumberOfArguments("latency|help");
}

List<string> latencyCommands = RespLatencyHelp.GetLatencyCommands();
while (!RespWriteUtils.TryWriteArrayLength(latencyCommands.Count, ref dcurr, dend))
SendAndReset();

foreach (string command in latencyCommands)
{
while (!RespWriteUtils.TryWriteSimpleString(command, ref dcurr, dend))
SendAndReset();
}
var latencyCommands = RespLatencyHelp.GetLatencyCommands();
WriteHelp(latencyCommands);

return true;
}
Expand Down
10 changes: 4 additions & 6 deletions libs/server/Metrics/Latency/RespLatencyHelp.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Collections.Generic;

namespace Garnet.server
{
/// <summary>
Expand All @@ -14,10 +12,10 @@ static class RespLatencyHelp
/// Get supported latency commands and a short description
/// </summary>
/// <returns></returns>
public static List<string> GetLatencyCommands()
public static string[] GetLatencyCommands()
{
return new List<string>()
{
return
[
"LATENCY <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
"HISTOGRAM [EVENT [EVENT...]]",
"\tReturn latency histogram of one or more <event> classes.",
Expand All @@ -27,7 +25,7 @@ public static List<string> GetLatencyCommands()
"\t(default: reset all data for all event classes).",
"HELP",
"\tPrints this help"
};
];
}
}
}
12 changes: 2 additions & 10 deletions libs/server/Metrics/Slowlog/RespSlowlogCommands.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Garnet.common;
Expand All @@ -23,15 +22,8 @@ private bool NetworkSlowLogHelp()
return AbortWithWrongNumberOfArguments(nameof(RespCommand.SLOWLOG_HELP));
}

List<string> slowLogCommands = RespSlowLogHelp.GetSlowLogCommands();
while (!RespWriteUtils.TryWriteArrayLength(slowLogCommands.Count, ref dcurr, dend))
SendAndReset();

foreach (string command in slowLogCommands)
{
while (!RespWriteUtils.TryWriteSimpleString(command, ref dcurr, dend))
SendAndReset();
}
var slowLogCommands = RespSlowLogHelp.GetSlowLogCommands();
WriteHelp(slowLogCommands);

return true;
}
Expand Down
Loading
Loading