mirror of
https://github.com/joyieldInc/predixy.git
synced 2025-12-24 14:36:42 +08:00
Change config description style
This commit is contained in:
parent
95f4580ccf
commit
dcdc9a1ba0
@ -1,83 +1,95 @@
|
||||
# CustomCommand section must be defined before Latency monitor to support all commands
|
||||
#
|
||||
# NOTE: only support maximum 16 custom commands
|
||||
#
|
||||
# [...] must be specify
|
||||
# (...) optional. it has default value
|
||||
#
|
||||
# CustomCommand [alias1] { ## module alias. just a delimter
|
||||
# [command1] { ## command string, must be lower case. i.e. setnx, expire, ...
|
||||
# (minArgs) (val) ## minimum arguments(including command itself). default is 2(key only)
|
||||
# (maxArgs) (val) ## maximum arguments(including command itself). default is 2(key only)
|
||||
# (mode) (val) ## a command mode Read/Write/Admin is exclusive. default is Write.
|
||||
# }
|
||||
# [command2] {
|
||||
# ...
|
||||
# }
|
||||
# ...
|
||||
# }
|
||||
#
|
||||
# default key position is first parameter. i.e. command1 key ...
|
||||
# if you want to use other position, add KeyAt2(key is second) or KeyAt3(key is third) to mode with '|'
|
||||
# i.e. mode Write|KeyAt2
|
||||
#
|
||||
# in case of 'mode KeyAt2', it will resolved as Write|KeyAt2
|
||||
## Custom Command
|
||||
## CustomCommand {
|
||||
## command { #command string, must be lowercase
|
||||
## [Mode read|write|admin[|[keyAt2|keyAt3]] #default write, default key position is 1
|
||||
## [MinArgs [2-]] #default 2, including command itself
|
||||
## [MaxArgs [2-]] #default 2, must be MaxArgs >= MinArgs
|
||||
## }...
|
||||
## }
|
||||
|
||||
# from redis source src/modules/hello.c
|
||||
CustomCommand hello {
|
||||
# hello.push.native key value
|
||||
hello.push.native {
|
||||
minArgs 3
|
||||
maxArgs 3
|
||||
mode Write
|
||||
}
|
||||
# hello.repl2 <list-key>
|
||||
# just skipped since minArgs = 2, maxArgs = 2, mode = Write are default values
|
||||
hello.repl2 {
|
||||
}
|
||||
# hello.toggle.case key
|
||||
# same as hello.repl2
|
||||
hello.toggle.case {
|
||||
}
|
||||
# hello.more.expire key milliseconds
|
||||
hello.more.expire {
|
||||
minArgs 3
|
||||
maxArgs 3
|
||||
}
|
||||
# hello.zsumrange key startscore endscore
|
||||
hello.zsumrange {
|
||||
minArgs 4
|
||||
maxArgs 4
|
||||
mode Read
|
||||
}
|
||||
# hello.lexrange key min_lex max_lex min_age max_age
|
||||
hello.lexrange {
|
||||
minArgs 6
|
||||
maxArgs 6
|
||||
mode Read
|
||||
}
|
||||
# hello.hcopy key srcfield dstfield
|
||||
hello.hcopy {
|
||||
minArgs 4
|
||||
maxArgs 4
|
||||
}
|
||||
}
|
||||
## This section must be defined before Latency monitor to support all commands
|
||||
## Currently support maximum 16 custom commands
|
||||
|
||||
## Example:
|
||||
#CustomCommand {
|
||||
##------------------------------------------------------------------------
|
||||
# custom.ttl {
|
||||
# Mode keyAt2
|
||||
# MinArgs 3
|
||||
# MaxArgs 3
|
||||
# }
|
||||
#### custom.ttl miliseconds key
|
||||
#### Mode = write|keyAt2, MinArgs/MaxArgs = 3 = command + miliseconds + key
|
||||
##------------------------------------------------------------------------
|
||||
## from redis source src/modules/hello.c
|
||||
# hello.push.native {
|
||||
# MinArgs 3
|
||||
# MaxArgs 3
|
||||
# }
|
||||
#### hello.push.native key value
|
||||
#### Mode = write, MinArgs/MaxArgs = 3 = command) + key + value
|
||||
##------------------------------------------------------------------------
|
||||
# hello.repl2 {
|
||||
# }
|
||||
#### hello.repl2 <list-key>
|
||||
#### Mode = write, MinArgs/MaxArgs = 2 = command + list-key
|
||||
##------------------------------------------------------------------------
|
||||
# hello.toggle.case {
|
||||
# }
|
||||
#### hello.toggle.case key
|
||||
#### Mode = write, MinArgs/MaxArgs = 2 = command + key
|
||||
##------------------------------------------------------------------------
|
||||
# hello.more.expire {
|
||||
# MinArgs 3
|
||||
# MaxArgs 3
|
||||
# }
|
||||
#### hello.more.expire key milliseconds
|
||||
#### Mode = write, MinArgs/MaxArgs = 3 = command + key + milliseconds
|
||||
##------------------------------------------------------------------------
|
||||
# hello.zsumrange {
|
||||
# MinArgs 4
|
||||
# MaxArgs 4
|
||||
# Mode read
|
||||
# }
|
||||
#### hello.zsumrange key startscore endscore
|
||||
#### Mode = read, MinArgs/MaxArgs = 4 = command + key + startscore + endscore
|
||||
##------------------------------------------------------------------------
|
||||
# hello.lexrange {
|
||||
# MinArgs 6
|
||||
# MaxArgs 6
|
||||
# Mode read
|
||||
# }
|
||||
#### hello.lexrange key min_lex max_lex min_age max_age
|
||||
#### Mode = read, MinArgs/MaxArgs = 6 = command + key + min_lex + max_lex + min_age + max_age
|
||||
##------------------------------------------------------------------------
|
||||
# hello.hcopy {
|
||||
# MinArgs 4
|
||||
# MaxArgs 4
|
||||
# }
|
||||
#### hello.hcopy key srcfield dstfield
|
||||
#### Mode = write, MinArgs/MaxArgs = 4 = command + key + srcfield) + dstfield
|
||||
##------------------------------------------------------------------------
|
||||
## from redis source src/modules/hellotype.c
|
||||
# hellotype.insert {
|
||||
# MinArgs 3
|
||||
# MaxArgs 3
|
||||
# }
|
||||
#### hellotype.insert key value
|
||||
#### Mode = write, MinArgs/MaxArgs = 3 = command + key + value
|
||||
##------------------------------------------------------------------------
|
||||
# hellotype.range {
|
||||
# MinArgs 4
|
||||
# MaxArgs 4
|
||||
# Mode read
|
||||
# }
|
||||
#### hellotype.range key first count
|
||||
#### Mode = read, MinArgs/MaxArgs = 4 = command + key + first + count
|
||||
##------------------------------------------------------------------------
|
||||
# hellotype.len {
|
||||
# Mode read
|
||||
# }
|
||||
#### hellotype.len key
|
||||
#### Mode = read, MinArgs/MaxArgs = 2 = command + key
|
||||
##------------------------------------------------------------------------
|
||||
#}
|
||||
|
||||
# from redis source src/modules/hellotype.c
|
||||
CustomCommand hellotype {
|
||||
# hellotype.insert key value
|
||||
hellotype.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
|
||||
}
|
||||
}
|
||||
|
||||
19
src/Conf.cpp
19
src/Conf.cpp
@ -381,13 +381,16 @@ void Conf::setCustomCommand(const ConfParser::Node* node)
|
||||
CustomCommandConf::init(cc, p->key.c_str(), Command::Sentinel);
|
||||
auto s = p->sub;
|
||||
for (;s ; s = s->next) {
|
||||
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)) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
if (cc.cmd.maxArgs < cc.cmd.minArgs) {
|
||||
Throw(InvalidValue, "%s:%d must be MaxArgs >= MinArgs", p->file, p->line);
|
||||
}
|
||||
Command::addCustomCommand(&cc.cmd);
|
||||
}
|
||||
}
|
||||
@ -405,15 +408,15 @@ bool Conf::setCommandMode(int& mode, const char* name, const ConfParser::Node* n
|
||||
std::string mask;
|
||||
std::istringstream is(n->val);
|
||||
while (std::getline(is, mask, '|')) {
|
||||
if ((strcasecmp(mask.c_str(), "Write") == 0)) {
|
||||
if ((strcasecmp(mask.c_str(), "write") == 0)) {
|
||||
mode |= Command::Write;
|
||||
} else if ((strcasecmp(mask.c_str(), "Read") == 0)) {
|
||||
} else if ((strcasecmp(mask.c_str(), "read") == 0)) {
|
||||
mode |= Command::Read;
|
||||
} else if ((strcasecmp(mask.c_str(), "Admin") == 0)) {
|
||||
} else if ((strcasecmp(mask.c_str(), "admin") == 0)) {
|
||||
mode |= Command::Admin;
|
||||
} else if ((strcasecmp(mask.c_str(), "KeyAt2") == 0)) {
|
||||
} else if ((strcasecmp(mask.c_str(), "keyAt2") == 0)) {
|
||||
mode |= Command::KeyAt2;
|
||||
} else if ((strcasecmp(mask.c_str(), "KeyAt3") == 0)) {
|
||||
} else if ((strcasecmp(mask.c_str(), "keyAt3") == 0)) {
|
||||
mode |= Command::KeyAt3;
|
||||
} else {
|
||||
Throw(InvalidValue, "%s:%d unknown mode %s", n->file, n->line, mask.c_str());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user