Skip to content

Commit

Permalink
COMMAND to work with optional data being not set. (microsoft#581)
Browse files Browse the repository at this point in the history
Resp output format of COMMAND family of commands should continue to work even for commands that are registered with missing optional data.
---------

Co-authored-by: Badrish Chandramouli <[email protected]>
  • Loading branch information
yrajas and badrishc authored Aug 9, 2024
1 parent 8eb7d5e commit 35dc23d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions libs/server/Resp/RespCommandsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,37 @@ public static bool TryGetRespCommandInfo(RespCommand cmd,
/// <returns>Serialized value</returns>
public string ToRespFormat()
{
var sb = new StringBuilder();
if (string.IsNullOrWhiteSpace(this.Name))
return "$-1\r\n";

var sb = new StringBuilder();
sb.Append("*10\r\n");
// 1) Name
sb.Append($"${this.Name.Length}\r\n{this.Name}\r\n");
// 2) Arity
sb.Append($":{this.Arity}\r\n");
// 3) Flags
sb.Append($"*{this.respFormatFlags.Length}\r\n");
foreach (var flag in this.respFormatFlags)
sb.Append($"+{flag}\r\n");
sb.Append($"*{this.respFormatFlags?.Length ?? 0}\r\n");
if (this.respFormatFlags != null && this.respFormatFlags.Length > 0)
{
foreach (var flag in this.respFormatFlags)
sb.Append($"+{flag}\r\n");
}

// 4) First key
sb.Append($":{this.FirstKey}\r\n");
// 5) Last key
sb.Append($":{this.LastKey}\r\n");
// 6) Step
sb.Append($":{this.Step}\r\n");
// 7) ACL categories
sb.Append($"*{this.respFormatAclCategories.Length}\r\n");
foreach (var aclCat in this.respFormatAclCategories)
sb.Append($"+@{aclCat}\r\n");
sb.Append($"*{this.respFormatAclCategories?.Length ?? 0}\r\n");
if (this.respFormatAclCategories != null && this.respFormatAclCategories.Length > 0)
{
foreach (var aclCat in this.respFormatAclCategories)
sb.Append($"+@{aclCat}\r\n");
}

// 8) Tips
var tipCount = this.Tips?.Length ?? 0;
sb.Append($"*{tipCount}\r\n");
Expand Down

0 comments on commit 35dc23d

Please sign in to comment.