This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 9294f8f7 Add dynamic key range generator with multiple range output
(#1541)
9294f8f7 is described below
commit 9294f8f78bb8d166672bf5b3fd7e2a0437f073b9
Author: clundro <[email protected]>
AuthorDate: Sun Jul 9 12:12:37 2023 +0800
Add dynamic key range generator with multiple range output (#1541)
Signed-off-by: clundro <[email protected]>
---
src/commands/commander.h | 30 +++++++++++++++++++++++-------
src/server/server.cc | 11 ++++++++++-
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/commands/commander.h b/src/commands/commander.h
index a2cda41b..874957a4 100644
--- a/src/commands/commander.h
+++ b/src/commands/commander.h
@@ -113,6 +113,8 @@ struct CommandKeyRange {
using CommandKeyRangeGen = std::function<CommandKeyRange(const
std::vector<std::string> &)>;
+using CommandKeyRangeVecGen = std::function<std::vector<CommandKeyRange>(const
std::vector<std::string> &)>;
+
struct CommandAttributes {
std::string name;
@@ -129,6 +131,9 @@ struct CommandAttributes {
// if key_range.first_key == -1, key_range_gen is used instead
CommandKeyRangeGen key_range_gen;
+ // if key_range.first_key == -2, key_range_vec_gen is used instead
+ CommandKeyRangeVecGen key_range_vec_gen;
+
CommanderFactory factory;
bool IsWrite() const { return (flags & kCmdWrite) != 0; }
@@ -186,6 +191,7 @@ auto MakeCmdAttr(const std::string &name, int arity, const
std::string &descript
ParseCommandFlags(description, name),
{first_key, last_key, key_step},
{},
+ {},
[]() -> std::unique_ptr<Commander> { return
std::unique_ptr<Commander>(new T()); }};
if ((first_key > 0 && key_step <= 0) || (first_key > 0 && last_key >= 0 &&
last_key < first_key)) {
@@ -198,13 +204,23 @@ auto MakeCmdAttr(const std::string &name, int arity,
const std::string &descript
template <typename T>
auto MakeCmdAttr(const std::string &name, int arity, const std::string
&description, const CommandKeyRangeGen &gen) {
- CommandAttributes attr{name,
- arity,
- description,
- ParseCommandFlags(description, name),
- {-1, 0, 0},
- gen,
- []() -> std::unique_ptr<Commander> { return
std::unique_ptr<Commander>(new T()); }};
+ CommandAttributes attr{
+ name, arity,
+ description, ParseCommandFlags(description, name),
+ {-1, 0, 0}, gen,
+ {}, []() -> std::unique_ptr<Commander> { return
std::unique_ptr<Commander>(new T()); }};
+
+ return attr;
+}
+
+template <typename T>
+auto MakeCmdAttr(const std::string &name, int arity, const std::string
&description,
+ const CommandKeyRangeVecGen &vec_gen) {
+ CommandAttributes attr{
+ name, arity,
+ description, ParseCommandFlags(description, name),
+ {-2, 0, 0}, {},
+ vec_gen, []() -> std::unique_ptr<Commander> { return
std::unique_ptr<Commander>(new T()); }};
return attr;
}
diff --git a/src/server/server.cc b/src/server/server.cc
index a5604496..ad00be43 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -1683,12 +1683,21 @@ void Server::UpdateWatchedKeysFromArgs(const
std::vector<std::string> &args, con
if (attr.IsWrite() && watched_key_size_ > 0) {
if (attr.key_range.first_key > 0) {
updateWatchedKeysFromRange(args, attr.key_range);
- } else if (attr.key_range.first_key < 0) {
+ } else if (attr.key_range.first_key == -1) {
redis::CommandKeyRange range = attr.key_range_gen(args);
if (range.first_key > 0) {
updateWatchedKeysFromRange(args, range);
}
+ } else if (attr.key_range.first_key == -2) {
+ std::vector<redis::CommandKeyRange> vec_range =
attr.key_range_vec_gen(args);
+
+ for (const auto &range : vec_range) {
+ if (range.first_key > 0) {
+ updateWatchedKeysFromRange(args, range);
+ }
+ }
+
} else {
// support commands like flushdb (write flag && key range {0,0,0})
updateAllWatchedKeys();