-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Compatibility] Added COMMAND GETKEYS and GETKEYSANDFLAGS command #888
base: main
Are you sure you want to change the base?
Changes from all commits
6460ad6
6a7f6b4
c6d0633
f5ec1cd
923664a
3516f7a
de1089c
fcca08b
9d4c36d
f503361
70efad2
50ac2be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Garnet.server | ||
{ | ||
/// <summary> | ||
/// Extension methods for the SessionParseState struct. | ||
/// </summary> | ||
internal static class SessionParseStateExtension | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods can be added to the existing Garnet.server/SessionParseStateExtensions.cs |
||
{ | ||
/// <summary> | ||
/// Tries to extract keys from the key specifications in the given RespCommandsInfo. | ||
/// </summary> | ||
/// <param name="state">The SessionParseState instance.</param> | ||
/// <param name="keySpecs">The RespCommandKeySpecification array contains the key specification</param> | ||
/// <param name="keys">The list to store extracted keys.</param> | ||
/// <returns>True if keys were successfully extracted, otherwise false.</returns> | ||
internal static bool TryExtractKeysFromSpecs(this ref SessionParseState state, RespCommandKeySpecification[] keySpecs, out List<ArgSlice> keys) | ||
{ | ||
keys = new(); | ||
|
||
foreach (var spec in keySpecs) | ||
{ | ||
if (!ExtractKeysFromSpec(ref state, keys, spec)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
internal static bool TryExtractKeyandFlagsFromSpecs(this ref SessionParseState state, RespCommandKeySpecification[] keySpecs, out List<ArgSlice> keys, out List<string[]> flags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming: TryExtractKeysAndFlagsFromSpecs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing XML comment |
||
{ | ||
keys = new(); | ||
flags = new(); | ||
|
||
foreach (var spec in keySpecs) | ||
{ | ||
var prevKeyCount = keys.Count; | ||
if (!ExtractKeysFromSpec(ref state, keys, spec)) | ||
{ | ||
return false; | ||
} | ||
|
||
var keyFlags = spec.RespFormatFlags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can return a slice of this array instead of creating this list There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't because we logic to skip and take like skip 1, take 1, skip 1 take 1.... or skip 2, take 1..... |
||
for (int i = prevKeyCount; i < keys.Count; i++) | ||
{ | ||
flags.Add(keyFlags); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static bool ExtractKeysFromSpec(ref SessionParseState state, List<ArgSlice> keys, RespCommandKeySpecification spec) | ||
{ | ||
int startIndex = 0; | ||
|
||
if (spec.BeginSearch is BeginSearchIndex bsIndex) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too, you can have an abstract method called GetStartIndex (or something similar) in BeginSearchKeySpecMethodBase that you can implement for each of the different types. |
||
{ | ||
startIndex = bsIndex.GetIndex(ref state); | ||
} | ||
else if (spec.BeginSearch is BeginSearchKeyword bsKeyword) | ||
{ | ||
if (!bsKeyword.TryGetStartFrom(ref state, out startIndex)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
if (startIndex < 0 || startIndex >= state.Count) | ||
return false; | ||
|
||
if (spec.FindKeys is FindKeysRange range) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this type matching you can have ExtractKeys defined as an abstract method in FindKeysKeySpecMethodBase |
||
{ | ||
range.ExtractKeys(ref state, startIndex, keys); | ||
} | ||
else if (spec.FindKeys is FindKeysKeyNum keyNum) | ||
{ | ||
keyNum.ExtractKeys(ref state, startIndex, keys); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here about running CommentInfoUpdater - #864 (comment)