Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-binbin committed Jan 25, 2024
1 parent f99a4eb commit e29a777
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/commands/cmd_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class CommandLMPop : public Commander {
// This parsing would always succeed as this cmd has been parsed before.
auto num_key = *ParseInt<int32_t>(args[1], 10);
range.last_key = range.first_key + num_key - 1;
range.store_key = 0;
return range;
};

Expand Down Expand Up @@ -446,6 +447,7 @@ class CommandBLMPop : public BlockingCommander {
// This parsing would always succeed as this cmd has been parsed before.
auto num_key = *ParseInt<int32_t>(args[2], 10);
range.last_key = range.first_key + num_key - 1;
range.store_key = 0;
return range;
};

Expand Down
6 changes: 3 additions & 3 deletions src/commands/cmd_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ class CommandZUnionStore : public Commander {

static CommandKeyRange Range(const std::vector<std::string> &args) {
int num_key = *ParseInt<int>(args[2], 10);
return {1, 3, 2 + num_key, 1};
return {3, 2 + num_key, 1, 1};
}

protected:
Expand All @@ -1251,7 +1251,7 @@ class CommandZInterStore : public CommandZUnionStore {

static CommandKeyRange Range(const std::vector<std::string> &args) {
int num_key = *ParseInt<int>(args[2], 10);
return {1, 3, 2 + num_key, 1};
return {3, 2 + num_key, 1, 1};
}
};

Expand Down Expand Up @@ -1505,7 +1505,7 @@ class CommandZDiffStore : public Commander {

static CommandKeyRange Range(const std::vector<std::string> &args) {
int num_key = *ParseInt<int>(args[2], 10);
return {1, 3, 2 + num_key, 1};
return {3, 2 + num_key, 1, 1};
}

protected:
Expand Down
31 changes: 5 additions & 26 deletions src/commands/commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ class CommanderWithParseMove : Commander {
using CommanderFactory = std::function<std::unique_ptr<Commander>()>;

struct CommandKeyRange {
// index of the store key in command tokens
// 0 stands for no store key, since the first index of command arguments is command name
int store_key;

// index of the first key in command tokens
// 0 stands for no key, since the first index of command arguments is command name
int first_key;
Expand All @@ -109,6 +105,10 @@ struct CommandKeyRange {
// step length of key position
// e.g. key step 2 means "key other key other ..." sequence
int key_step;

// index of the store key in command tokens
// 0 stands for no store key, since the first index of command arguments is command name
int store_key;
};

using CommandKeyRangeGen = std::function<CommandKeyRange(const std::vector<std::string> &)>;
Expand Down Expand Up @@ -201,7 +201,7 @@ auto MakeCmdAttr(const std::string &name, int arity, const std::string &descript
description,
ParseCommandFlags(description, name),
flag_gen,
{0, first_key, last_key, key_step},
{first_key, last_key, key_step},
{},
{},
[]() -> std::unique_ptr<Commander> { return std::unique_ptr<Commander>(new T()); }};
Expand All @@ -214,27 +214,6 @@ auto MakeCmdAttr(const std::string &name, int arity, const std::string &descript
return attr;
}

template <typename T>
auto MakeCmdAttr(const std::string &name, int arity, const std::string &description, int store_key, int first_key,
int last_key, int key_step, const AdditionalFlagGen &flag_gen = {}) {
CommandAttributes attr{name,
arity,
description,
ParseCommandFlags(description, name),
flag_gen,
{store_key, first_key, last_key, key_step},
{},
{},
[]() -> std::unique_ptr<Commander> { return std::unique_ptr<Commander>(new T()); }};

if ((store_key < 0) || (first_key > 0 && key_step <= 0) || (first_key > 0 && last_key >= 0 && last_key < first_key)) {
std::cout << fmt::format("Encountered invalid key range in command {}", name) << std::endl;
std::abort();
}

return attr;
}

template <typename T>
auto MakeCmdAttr(const std::string &name, int arity, const std::string &description, const CommandKeyRangeGen &gen,
const AdditionalFlagGen &flag_gen = {}) {
Expand Down
2 changes: 1 addition & 1 deletion x.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def test_go(dir: str, cli_path: str, rest: List[str]) -> None:
)
parser_test_go.add_argument('dir', metavar='BUILD_DIR', nargs='?', default='build',
help="directory including kvrocks build files")
parser_test_go.add_argument('--cli-path', default='redis-cli', help="path of redis-cli to test kvrocks")
parser_test_go.add_argument('--cli-path', default='/Users/binbinzhu/github/redis/src/redis-cli', help="path of redis-cli to test kvrocks")
parser_test_go.add_argument('rest', nargs=REMAINDER, help="the rest of arguments to forward to go test")
parser_test_go.set_defaults(func=test_go)

Expand Down

0 comments on commit e29a777

Please sign in to comment.