From 5d9cd99270f9aaa504bdae39b181add74c9081a5 Mon Sep 17 00:00:00 2001 From: Yoon Date: Thu, 5 Apr 2018 16:17:47 +0900 Subject: [PATCH 1/9] Add support custom commands Custom commands are from redis module can be added up to 16(currently). Configuration is like below. CustomCommand { hello { # hello is command, must be lower case. # this command has 2 or 3 parameters and first argument is key minArgs 2 # minimum arguments(including command itself) maxArgs 3 # maximum arguments(including command itself) mode Write,Read # this command is writable and readable # mode value can be Admin, Private, NoKey, MultiKey, SMultiKey, MultiKeyVal, KeyAt2, KeyAt3 } newcommand { # default minArgs = 1, maxArgs = 1 and mode = Write mode Admin } ... } --- src/Command.cpp | 16 +++++++-- src/Command.h | 9 +++-- src/Conf.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++ src/Conf.h | 14 +++++++- src/LatencyMonitor.h | 2 +- 5 files changed, 114 insertions(+), 6 deletions(-) diff --git a/src/Command.cpp b/src/Command.cpp index 0b5df05..5821613 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -10,7 +10,7 @@ #include "String.h" #include "Command.h" -const Command Command::CmdPool[Sentinel] = { +Command Command::CmdPool[AvailableCommands] = { {None, "", 0, MaxArgs, Read}, {Ping, "ping", 1, 2, Read}, {PingServ, "ping", 1, 2, Inner}, @@ -171,11 +171,14 @@ const Command Command::CmdPool[Sentinel] = { {SubMsg, "\000SubMsg", 0, 0, Admin} }; +int Command::Sentinel = Command::MaxCommands; Command::CommandMap Command::CmdMap; + void Command::init() { int type = 0; - for (auto& i : CmdPool) { + for (auto j = 0; j < MaxCommands; j++) { + const auto& i = CmdPool[j]; if (i.type != type) { Throw(InitFail, "command %s unmatch the index in commands table", i.name); } @@ -187,3 +190,12 @@ void Command::init() } } +void Command::addCustomCommand(const Command *p) { + if (nullptr != find(p->name)) { + Throw(InitFail, "custom command %s is duplicated", p->name); + } + CmdPool[Sentinel] = *p; + CmdMap[p->name] = &CmdPool[Sentinel]; + Sentinel++; +} + diff --git a/src/Command.h b/src/Command.h index eb15709..5555621 100644 --- a/src/Command.h +++ b/src/Command.h @@ -8,6 +8,7 @@ #define _PREDIXY_COMMAND_H_ #include +#include #include "Exception.h" #include "HashFunc.h" @@ -189,7 +190,8 @@ public: Unsubscribe, SubMsg, - Sentinel + MaxCommands, + AvailableCommands = MaxCommands + 128, }; enum Mode { @@ -242,6 +244,7 @@ public: if (cursor < Sentinel) { return &CmdPool[cursor++]; } + return nullptr; } static const Command* find(const String& cmd) @@ -249,9 +252,11 @@ public: auto it = CmdMap.find(cmd); return it == CmdMap.end() ? nullptr : it->second; } + static void addCustomCommand(const Command *pc); + static int Sentinel; private: static const int MaxArgs = 100000000; - static const Command CmdPool[Sentinel]; + static Command CmdPool[]; class H { public: diff --git a/src/Conf.cpp b/src/Conf.cpp index f5325fa..ff38ee1 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include "LogFileSink.h" #include "ServerPool.h" @@ -32,6 +33,15 @@ bool ServerConf::parse(ServerConf& s, const char* str) return !s.addr.empty(); } +void CustomCommandConf::init(CustomCommandConf&c, const char* name, const int type) { + c.name = name; + c.cmd.type = (Command::Type)type; + c.cmd.name = c.name.c_str(); + c.cmd.minArgs = 1; + c.cmd.maxArgs = 1; + c.cmd.mode = Command::Write; +} + Conf::Conf(): mBind("0.0.0.0:7617"), mWorkerThreads(1), @@ -157,6 +167,8 @@ void Conf::setGlobal(const ConfParser::Node* node) sentinelServerPool = p; } else if (strcasecmp(p->key.c_str(), "DataCenter") == 0) { dataCenter = p; + } else if (strcasecmp(p->key.c_str(), "CustomCommand") == 0) { + setCustomCommand(p); } else { Throw(UnknownKey, "%s:%d unknown key %s", p->file, p->line, p->key.c_str()); } @@ -358,6 +370,73 @@ void Conf::setDataCenter(const ConfParser::Node* node) } } +void Conf::setCustomCommand(const ConfParser::Node* node) +{ + if (!node->sub) { + Throw(InvalidValue, "%s:%d CustomCommand require scope value", node->file, node->line); + } + for (auto p = node->sub; p; p = p->next) { + if (Command::Sentinel >= Command::AvailableCommands) { + Throw(InvalidValue, "%s:%d Too many custom commands", node->file, node->line); + } + mCustomCommands.push_back(CustomCommandConf{}); + auto& cc = mCustomCommands.back(); + CustomCommandConf::init(cc, p->key.c_str(), Command::Sentinel); + auto s = p->sub; + if (!s) { + Throw(InvalidValue, "%s:%d CustomCommand.Command require scope value", + node->file, node->line); + } + for (;s ; s = s->next) { + setInt(cc.cmd.minArgs, "minArgs", s, 1); + setInt(cc.cmd.maxArgs, "maxArgs", s, 1, 9999); + setCommandMode(cc.cmd.mode, "mode", s); + } + Command::addCustomCommand(&cc.cmd); + } +} + +bool Conf::setCommandMode(int& mode, const char* name, const ConfParser::Node* n, const int defaultMode) +{ + if (strcasecmp(name, n->key.c_str()) == 0) { + if (n->val.size() == 0) { + mode = defaultMode; + } else { + mode = Command::Unknown; + } + std::string mask; + std::istringstream is(n->val); + while (std::getline(is, mask, ',')) { + if ((strcasecmp(mask.c_str(), "Write") == 0)) { + mode |= Command::Write; + } else if ((strcasecmp(mask.c_str(), "Read") == 0)) { + mode |= Command::Read; + } else if ((strcasecmp(mask.c_str(), "Admin") == 0)) { + mode |= Command::Admin; + } else if ((strcasecmp(mask.c_str(), "Private") == 0)) { + mode |= Command::Private; + } else if ((strcasecmp(mask.c_str(), "NoKey") == 0)) { + mode |= Command::NoKey; + } else if ((strcasecmp(mask.c_str(), "MultiKey") == 0)) { + mode |= Command::MultiKey; + } else if ((strcasecmp(mask.c_str(), "SMultiKey") == 0)) { + mode |= Command::SMultiKey; + } else if ((strcasecmp(mask.c_str(), "MultiKeyVal") == 0)) { + mode |= Command::MultiKeyVal; + } else if ((strcasecmp(mask.c_str(), "KeyAt2") == 0)) { + mode |= Command::KeyAt2; + } else if ((strcasecmp(mask.c_str(), "KeyAt3") == 0)) { + mode |= Command::KeyAt3; + } else { + Throw(InvalidValue, "%s:%d %s %s is not an mode", + n->file, n->line, name, n->val.c_str()); + } + } + return true; + } + return false; +} + void Conf::setDC(DCConf& dc, const ConfParser::Node* node) { if (!node->sub) { diff --git a/src/Conf.h b/src/Conf.h index 04e9a17..1b9e002 100644 --- a/src/Conf.h +++ b/src/Conf.h @@ -19,6 +19,7 @@ #include "Distribution.h" #include "ConfParser.h" #include "Auth.h" +#include "Command.h" struct AuthConf { @@ -89,10 +90,18 @@ struct DCConf struct LatencyMonitorConf { std::string name; - std::bitset cmds; + std::bitset cmds; std::vector timeSpan;//us }; +struct CustomCommandConf +{ + std::string name; + Command cmd; + + static void init(CustomCommandConf &c, const char* name, const int type); +}; + class Conf { public: @@ -201,6 +210,8 @@ private: void setDC(DCConf& dc, const ConfParser::Node* n); void setReadPolicy(ReadPolicyConf& c, const ConfParser::Node* n); void setLatencyMonitor(LatencyMonitorConf& m, const ConfParser::Node* n); + void setCustomCommand(const ConfParser::Node* n); + bool setCommandMode(int& mode, const char* name, const ConfParser::Node* n, const int defaultMode = Command::Write); private: std::string mName; std::string mBind; @@ -220,6 +231,7 @@ private: std::vector mDCConfs; std::string mLocalDC; std::vector mLatencyMonitors; + std::vector mCustomCommands; }; diff --git a/src/LatencyMonitor.h b/src/LatencyMonitor.h index 866a400..55dc3a3 100644 --- a/src/LatencyMonitor.h +++ b/src/LatencyMonitor.h @@ -98,7 +98,7 @@ public: Buffer* output(Buffer* buf) const; private: String mName; - const std::bitset* mCmds; + const std::bitset* mCmds; std::vector mTimeSpan; TimeSpan mLast; }; From 133e30318809f4d684cc92429f28775a46dd97aa Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 13:54:35 +0900 Subject: [PATCH 2/9] Apply @fortrue's comments --- src/Command.cpp | 3 +++ src/Command.h | 3 ++- src/Conf.cpp | 25 ++++++++----------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Command.cpp b/src/Command.cpp index 5821613..7f3b9f5 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -191,6 +191,9 @@ void Command::init() } void Command::addCustomCommand(const Command *p) { + if (Sentinel >= AvailableCommands) { + Throw(InitFail, "too many custom commands(>%d)", MaxCustomCommands); + } if (nullptr != find(p->name)) { Throw(InitFail, "custom command %s is duplicated", p->name); } diff --git a/src/Command.h b/src/Command.h index 5555621..474df61 100644 --- a/src/Command.h +++ b/src/Command.h @@ -191,7 +191,8 @@ public: SubMsg, MaxCommands, - AvailableCommands = MaxCommands + 128, + MaxCustomCommands = 16, + AvailableCommands = MaxCommands + MaxCustomCommands, }; enum Mode { diff --git a/src/Conf.cpp b/src/Conf.cpp index ff38ee1..c95d921 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -37,7 +37,7 @@ void CustomCommandConf::init(CustomCommandConf&c, const char* name, const int ty c.name = name; c.cmd.type = (Command::Type)type; c.cmd.name = c.name.c_str(); - c.cmd.minArgs = 1; + c.cmd.minArgs = 2; c.cmd.maxArgs = 1; c.cmd.mode = Command::Write; } @@ -376,9 +376,6 @@ void Conf::setCustomCommand(const ConfParser::Node* node) Throw(InvalidValue, "%s:%d CustomCommand require scope value", node->file, node->line); } for (auto p = node->sub; p; p = p->next) { - if (Command::Sentinel >= Command::AvailableCommands) { - Throw(InvalidValue, "%s:%d Too many custom commands", node->file, node->line); - } mCustomCommands.push_back(CustomCommandConf{}); auto& cc = mCustomCommands.back(); CustomCommandConf::init(cc, p->key.c_str(), Command::Sentinel); @@ -388,9 +385,13 @@ void Conf::setCustomCommand(const ConfParser::Node* node) node->file, node->line); } for (;s ; s = s->next) { - setInt(cc.cmd.minArgs, "minArgs", s, 1); - setInt(cc.cmd.maxArgs, "maxArgs", s, 1, 9999); - setCommandMode(cc.cmd.mode, "mode", s); + if (setInt(cc.cmd.minArgs, "minArgs", s, 2)) { + } else if (setInt(cc.cmd.maxArgs, "maxArgs", s, 2, 9999)) { + } else if (setCommandMode(cc.cmd.mode, "mode", s)) { + } else { + Throw(UnknownKey, "%s:%d unknown key %s", + s->file, s->line, s->key.c_str()); + } } Command::addCustomCommand(&cc.cmd); } @@ -413,16 +414,6 @@ bool Conf::setCommandMode(int& mode, const char* name, const ConfParser::Node* n mode |= Command::Read; } else if ((strcasecmp(mask.c_str(), "Admin") == 0)) { mode |= Command::Admin; - } else if ((strcasecmp(mask.c_str(), "Private") == 0)) { - mode |= Command::Private; - } else if ((strcasecmp(mask.c_str(), "NoKey") == 0)) { - mode |= Command::NoKey; - } else if ((strcasecmp(mask.c_str(), "MultiKey") == 0)) { - mode |= Command::MultiKey; - } else if ((strcasecmp(mask.c_str(), "SMultiKey") == 0)) { - mode |= Command::SMultiKey; - } else if ((strcasecmp(mask.c_str(), "MultiKeyVal") == 0)) { - mode |= Command::MultiKeyVal; } else if ((strcasecmp(mask.c_str(), "KeyAt2") == 0)) { mode |= Command::KeyAt2; } else if ((strcasecmp(mask.c_str(), "KeyAt3") == 0)) { From 15d51cb931b3cd4176b03d52a910da48e8f54094 Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 14:06:22 +0900 Subject: [PATCH 3/9] Fix tab --- src/Command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command.h b/src/Command.h index 474df61..1b43e92 100644 --- a/src/Command.h +++ b/src/Command.h @@ -191,7 +191,7 @@ public: SubMsg, MaxCommands, - MaxCustomCommands = 16, + MaxCustomCommands = 16, AvailableCommands = MaxCommands + MaxCustomCommands, }; enum Mode From edbe04b8181c9fc6f74757c3a90dac5a12aac78f Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 18:00:27 +0900 Subject: [PATCH 4/9] Add sample custom command configuration(conf/command.conf) --- conf/command.conf | 93 +++++++++++++++++++++++++++++++++++++++++++++++ conf/predixy.conf | 6 +++ 2 files changed, 99 insertions(+) create mode 100644 conf/command.conf diff --git a/conf/command.conf b/conf/command.conf new file mode 100644 index 0000000..d966f6a --- /dev/null +++ b/conf/command.conf @@ -0,0 +1,93 @@ +CustomCommand { + # + hello.simple { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.native { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.call { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.call2 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.sumlen { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.splice { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.splice.auto { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.ran.array { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.repl1 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.repl2 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.toggle.case { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.more.expire { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.lexrange { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.hcopy { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.leftpad { + minArgs 3 + maxArgs 3 + mode Read + } +} + diff --git a/conf/predixy.conf b/conf/predixy.conf index aa76713..6f4be1d 100644 --- a/conf/predixy.conf +++ b/conf/predixy.conf @@ -93,6 +93,12 @@ Include try.conf # Include dc.conf +################################### LATENCY #################################### +## Custom command define, see command.conf +## must defined before Latency monitor +#Include command.conf + + ################################### LATENCY #################################### ## Latency monitor define, see latency.conf Include latency.conf From e290f277450719a1edacce02f270dc6bd9df5337 Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 18:06:14 +0900 Subject: [PATCH 5/9] Add a custom command config(conf/command.conf) --- conf/command.conf | 123 +++++++++++++++------------------------ conf/command.conf.sample | 108 ++++++++++++++++++++++++++++++++++ conf/predixy.conf | 3 +- 3 files changed, 157 insertions(+), 77 deletions(-) create mode 100644 conf/command.conf.sample diff --git a/conf/command.conf b/conf/command.conf index d966f6a..0e06a56 100644 --- a/conf/command.conf +++ b/conf/command.conf @@ -1,93 +1,66 @@ +# CustomCommand section must be defined before Latency monitor to support all commands +# +# NOTE: only support maximum 16 custom commands + CustomCommand { - # - hello.simple { - minArgs 3 - maxArgs 3 - mode Read + # from redis source src/modules/hello.c + # hello.push.native key value + hello.push.native { # name of command, must be lowercase. + # key parameter is located at first argument. i.e. command key ... + # Currently support only 1 key with first argument. + minArgs 3 # minimum arguments(including command itself), default is 2(key only) + maxArgs 3 # maximum arguments(including command itself), default is 2(key only) + mode Read,Write # behavior or permission. Currently support Read, Write, Admin } - # - hello.push.native { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.push.call { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.push.call2 { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.sumlen { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.splice { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.splice.auto { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.ran.array { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.repl1 { - minArgs 3 - maxArgs 3 - mode Read - } - # + # hello.repl2 + # just skipped since minArgs = 2, maxArgs = 2 are default values hello.repl2 { - minArgs 3 - maxArgs 3 - mode Read + mode Read,Write } - # + # hello.toggle.case key hello.toggle.case { - minArgs 3 - maxArgs 3 - mode Read + mode Read,Write } - # + # hello.more.expire key milliseconds hello.more.expire { minArgs 3 maxArgs 3 - mode Read + mode Read,Write } - # + # hello.zsumrange key startscore endscore + hello.zsumrange { + minArgs 4 + maxArgs 4 + mode Read,Write + } + # hello.lexrange key min_lex max_lex min_age max_age hello.lexrange { - minArgs 3 - maxArgs 3 - mode Read + minArgs 6 + maxArgs 6 + mode Read,Write } - # + # hello.hcopy key srcfield dstfield hello.hcopy { - minArgs 3 - maxArgs 3 - mode Read + minArgs 4 + maxArgs 4 + mode Read,Write } - # - hello.leftpad { + + # from redis source src/modules/hellotype.c + # hellotype.insert key value + hello.insert { minArgs 3 maxArgs 3 - mode Read + mode Read,Write + } + # hellotype.range key first count + hellotype.range { + minArgs 4 + maxArgs 4 + mode Read,Write + } + # hellotype.len key + hello.len { + mode Read,Wrie } } - diff --git a/conf/command.conf.sample b/conf/command.conf.sample new file mode 100644 index 0000000..6ca0abb --- /dev/null +++ b/conf/command.conf.sample @@ -0,0 +1,108 @@ +CustomCommand { + # + hello.simple { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.native { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.call { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.push.call2 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.sumlen { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.splice { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.list.splice.auto { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.ran.array { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.repl1 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.repl2 { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.toggle.case { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.more.expire { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.lexrange { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.hcopy { + minArgs 3 + maxArgs 3 + mode Read + } + # + hello.leftpad { + minArgs 3 + maxArgs 3 + mode Read + } + # hellotype.insert key value + hello.insert { + minArgs 3 + maxArgs 3 + } + # hellotype.range key first count + hellotype.range { + minArgs 4 + maxArgs 4 + mode Read + } + # hellotype.len key + hello.len { + mode Read + } +} + diff --git a/conf/predixy.conf b/conf/predixy.conf index 6f4be1d..ae50895 100644 --- a/conf/predixy.conf +++ b/conf/predixy.conf @@ -95,10 +95,9 @@ Include try.conf ################################### LATENCY #################################### ## Custom command define, see command.conf -## must defined before Latency monitor +## must defined before Latency monitor define #Include command.conf - ################################### LATENCY #################################### ## Latency monitor define, see latency.conf Include latency.conf From 7fb9187dedeb46a4e83e530707ed64bc19809a1e Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 18:07:56 +0900 Subject: [PATCH 6/9] Add a configuration for custom commands(conf/command.conf) --- conf/command.conf.sample | 108 --------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 conf/command.conf.sample diff --git a/conf/command.conf.sample b/conf/command.conf.sample deleted file mode 100644 index 6ca0abb..0000000 --- a/conf/command.conf.sample +++ /dev/null @@ -1,108 +0,0 @@ -CustomCommand { - # - hello.simple { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.push.native { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.push.call { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.push.call2 { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.sumlen { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.splice { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.list.splice.auto { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.ran.array { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.repl1 { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.repl2 { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.toggle.case { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.more.expire { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.lexrange { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.hcopy { - minArgs 3 - maxArgs 3 - mode Read - } - # - hello.leftpad { - minArgs 3 - maxArgs 3 - mode Read - } - # hellotype.insert key value - hello.insert { - minArgs 3 - maxArgs 3 - } - # hellotype.range key first count - hellotype.range { - minArgs 4 - maxArgs 4 - mode Read - } - # hellotype.len key - hello.len { - mode Read - } -} - From 7812aa8c4fd20215ef3ce19b4316e9b8706c78ef Mon Sep 17 00:00:00 2001 From: Yoon Date: Fri, 6 Apr 2018 18:18:12 +0900 Subject: [PATCH 7/9] Fix typos --- conf/predixy.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/predixy.conf b/conf/predixy.conf index ae50895..06e4c83 100644 --- a/conf/predixy.conf +++ b/conf/predixy.conf @@ -95,7 +95,7 @@ Include try.conf ################################### LATENCY #################################### ## Custom command define, see command.conf -## must defined before Latency monitor define +## must be defined before Latency monitor #Include command.conf ################################### LATENCY #################################### From 2d93868e823d586162f8d50caee3921015bcb933 Mon Sep 17 00:00:00 2001 From: Yoon Date: Mon, 9 Apr 2018 10:12:15 +0900 Subject: [PATCH 8/9] Apply comments #27 and change default mode for custom command conf --- conf/command.conf | 14 +++----------- conf/predixy.conf | 2 +- src/Conf.cpp | 4 ++-- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/conf/command.conf b/conf/command.conf index 0e06a56..d3704b8 100644 --- a/conf/command.conf +++ b/conf/command.conf @@ -10,40 +10,35 @@ CustomCommand { # Currently support only 1 key with first argument. minArgs 3 # minimum arguments(including command itself), default is 2(key only) maxArgs 3 # maximum arguments(including command itself), default is 2(key only) - mode Read,Write # behavior or permission. Currently support Read, Write, Admin + mode Read,Write # a command mode Read/Write/Admin is exclusive, Conf.cpp should check this. + # default is Read, Write } # hello.repl2 - # just skipped since minArgs = 2, maxArgs = 2 are default values + # just skipped since minArgs = 2, maxArgs = 2, mode = Read,Write are default values hello.repl2 { - mode Read,Write } # hello.toggle.case key hello.toggle.case { - mode Read,Write } # hello.more.expire key milliseconds hello.more.expire { minArgs 3 maxArgs 3 - mode Read,Write } # hello.zsumrange key startscore endscore hello.zsumrange { minArgs 4 maxArgs 4 - mode Read,Write } # hello.lexrange key min_lex max_lex min_age max_age hello.lexrange { minArgs 6 maxArgs 6 - mode Read,Write } # hello.hcopy key srcfield dstfield hello.hcopy { minArgs 4 maxArgs 4 - mode Read,Write } # from redis source src/modules/hellotype.c @@ -51,16 +46,13 @@ CustomCommand { hello.insert { minArgs 3 maxArgs 3 - mode Read,Write } # hellotype.range key first count hellotype.range { minArgs 4 maxArgs 4 - mode Read,Write } # hellotype.len key hello.len { - mode Read,Wrie } } diff --git a/conf/predixy.conf b/conf/predixy.conf index 06e4c83..a9f3ae1 100644 --- a/conf/predixy.conf +++ b/conf/predixy.conf @@ -93,7 +93,7 @@ Include try.conf # Include dc.conf -################################### LATENCY #################################### +################################### COMMAND #################################### ## Custom command define, see command.conf ## must be defined before Latency monitor #Include command.conf diff --git a/src/Conf.cpp b/src/Conf.cpp index c95d921..44dd0e9 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -38,8 +38,8 @@ void CustomCommandConf::init(CustomCommandConf&c, const char* name, const int ty c.cmd.type = (Command::Type)type; c.cmd.name = c.name.c_str(); c.cmd.minArgs = 2; - c.cmd.maxArgs = 1; - c.cmd.mode = Command::Write; + c.cmd.maxArgs = 2; + c.cmd.mode = Command::Write|Command::Read; } Conf::Conf(): From a0a9d818dfd05e49b1e4054757b82d6d14af1d1f Mon Sep 17 00:00:00 2001 From: Yoon Date: Mon, 9 Apr 2018 12:48:30 +0900 Subject: [PATCH 9/9] Change custom command default mode to Write --- conf/command.conf | 12 ++++++++++-- src/Conf.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/conf/command.conf b/conf/command.conf index d3704b8..22ddd4f 100644 --- a/conf/command.conf +++ b/conf/command.conf @@ -10,35 +10,40 @@ CustomCommand { # Currently support only 1 key with first argument. minArgs 3 # minimum arguments(including command itself), default is 2(key only) maxArgs 3 # maximum arguments(including command itself), default is 2(key only) - mode Read,Write # a command mode Read/Write/Admin is exclusive, Conf.cpp should check this. - # default is Read, Write + mode Read,Write # a command mode Read/Write/Admin is exclusive, default is Write } # hello.repl2 # just skipped since minArgs = 2, maxArgs = 2, mode = Read,Write are default values hello.repl2 { + mode Read,Write } # hello.toggle.case key hello.toggle.case { + mode Read,Write } # hello.more.expire key milliseconds hello.more.expire { minArgs 3 maxArgs 3 + mode Read,Write } # hello.zsumrange key startscore endscore hello.zsumrange { minArgs 4 maxArgs 4 + mode Read,Write } # hello.lexrange key min_lex max_lex min_age max_age hello.lexrange { minArgs 6 maxArgs 6 + mode Read,Write } # hello.hcopy key srcfield dstfield hello.hcopy { minArgs 4 maxArgs 4 + mode Read,Write } # from redis source src/modules/hellotype.c @@ -46,13 +51,16 @@ CustomCommand { hello.insert { minArgs 3 maxArgs 3 + mode Read,Write } # hellotype.range key first count hellotype.range { minArgs 4 maxArgs 4 + mode Read,Write } # hellotype.len key hello.len { + mode Read,Write } } diff --git a/src/Conf.cpp b/src/Conf.cpp index 44dd0e9..4547b21 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -39,7 +39,7 @@ void CustomCommandConf::init(CustomCommandConf&c, const char* name, const int ty c.cmd.name = c.name.c_str(); c.cmd.minArgs = 2; c.cmd.maxArgs = 2; - c.cmd.mode = Command::Write|Command::Read; + c.cmd.mode = Command::Write; } Conf::Conf():