Skip to content

Commit

Permalink
Add pkpatternmatchdel cmd (OpenAtomFoundation#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
justforfun1323 authored and whoiami committed Sep 4, 2019
1 parent 14b0ccb commit c16e36d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
15 changes: 15 additions & 0 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,19 @@ class TcmallocCmd : public Cmd {
virtual void DoInitial() override;
};
#endif

class PKPatternMatchDelCmd : public Cmd {
public:
PKPatternMatchDelCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual Cmd* Clone() override {
return new PKPatternMatchDelCmd(*this);
}

private:
blackwidow::DataType type_;
std::string pattern_;
virtual void DoInitial() override;
};
#endif // PIKA_ADMIN_H_
1 change: 1 addition & 0 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const std::string kCmdNamePadding = "padding";
#ifdef TCMALLOC_EXTENSION
const std::string kCmdNameTcmalloc = "tcmalloc";
#endif
const std::string kCmdNamePKPatternMatchDel = "pkpatternmatchdel";

//Kv
const std::string kCmdNameSet = "set";
Expand Down
2 changes: 1 addition & 1 deletion include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static std::set<std::string> ShardingModeNotSupportCommands {
kCmdNameSMove, kCmdNameBitOp, kCmdNamePfAdd,
kCmdNamePfCount, kCmdNamePfMerge, kCmdNameGeoAdd,
kCmdNameGeoPos, kCmdNameGeoDist, kCmdNameGeoHash,
kCmdNameGeoRadius, kCmdNameGeoRadiusByMember};
kCmdNameGeoRadius, kCmdNameGeoRadiusByMember, kCmdNamePKPatternMatchDel};


extern PikaConf *g_pika_conf;
Expand Down
32 changes: 32 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1928,3 +1928,35 @@ void TcmallocCmd::Do(std::shared_ptr<Partition> partition) {
}
}
#endif

void PKPatternMatchDelCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNamePKPatternMatchDel);
return;
}
pattern_ = argv_[1];
if (!strcasecmp(argv_[2].data(), "set")) {
type_ = blackwidow::kSets;
} else if (!strcasecmp(argv_[2].data(), "list")) {
type_ = blackwidow::kLists;
} else if (!strcasecmp(argv_[2].data(), "string")) {
type_ = blackwidow::kStrings;
} else if (!strcasecmp(argv_[2].data(), "zset")) {
type_ = blackwidow::kZSets;
} else if (!strcasecmp(argv_[2].data(), "hash")) {
type_ = blackwidow::kHashes;
} else {
res_.SetRes(CmdRes::kInvalidDbType, kCmdNamePKPatternMatchDel);
return;
}
}

void PKPatternMatchDelCmd::Do(std::shared_ptr<Partition> partition) {
int ret = 0;
rocksdb::Status s = partition->db()->PKPatternMatchDel(type_, pattern_, &ret);
if (s.ok()) {
res_.AppendInteger(ret);
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
}
}
10 changes: 6 additions & 4 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void InitCmdTable(std::unordered_map<std::string, Cmd*> *cmd_table) {
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameSlowlog, slowlogptr));
Cmd* paddingptr = new PaddingCmd(kCmdNamePadding, 2, kCmdFlagsWrite | kCmdFlagsAdmin);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNamePadding, paddingptr));
Cmd* pkpatternmatchdelptr = new PKPatternMatchDelCmd(kCmdNamePKPatternMatchDel, 3, kCmdFlagsWrite | kCmdFlagsAdmin);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNamePKPatternMatchDel, pkpatternmatchdelptr));

// Slots related
Cmd* slotsinfoptr = new SlotsInfoCmd(kCmdNameSlotsInfo, -1, kCmdFlagsRead | kCmdFlagsAdmin);
Expand Down Expand Up @@ -370,11 +372,11 @@ void InitCmdTable(std::unordered_map<std::string, Cmd*> *cmd_table) {
Cmd* zremrangebylexptr = new ZRemrangebylexCmd(kCmdNameZRemrangebylex, 4, kCmdFlagsWrite | kCmdFlagsSinglePartition | kCmdFlagsZset);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameZRemrangebylex, zremrangebylexptr));
////ZPopmax
Cmd* zpopmax = new ZPopmaxCmd(kCmdNameZPopmax, -2, kCmdFlagsWrite | kCmdFlagsSinglePartition | kCmdFlagsZset);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameZPopmax, zpopmax));
Cmd* zpopmaxptr = new ZPopmaxCmd(kCmdNameZPopmax, -2, kCmdFlagsWrite | kCmdFlagsSinglePartition | kCmdFlagsZset);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameZPopmax, zpopmaxptr));
////ZPopmin
Cmd* zpopmin = new ZPopminCmd(kCmdNameZPopmin, -2, kCmdFlagsWrite | kCmdFlagsSinglePartition | kCmdFlagsZset);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameZPopmin, zpopmin));
Cmd* zpopminptr = new ZPopminCmd(kCmdNameZPopmin, -2, kCmdFlagsWrite | kCmdFlagsSinglePartition | kCmdFlagsZset);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameZPopmin, zpopminptr));

//Set
////SAddCmd
Expand Down

0 comments on commit c16e36d

Please sign in to comment.