Skip to content

Commit

Permalink
feat: add pkhash tests and hash basic cmd
Browse files Browse the repository at this point in the history
add  new test cases for pkhash cmd below

* PKHSetex PKHExists PKHDel PKHLen PKHStrlen

* PKHIncrby PKHMSet PKHMSetex PKHMGet PKHKeys

* PKHVals PKHGetall PKHScan
  • Loading branch information
bigdaronlee163 authored and bgl committed Sep 29, 2024
1 parent 9bd2c26 commit 9d208a6
Show file tree
Hide file tree
Showing 12 changed files with 3,332 additions and 182 deletions.
3 changes: 1 addition & 2 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const std::string kCmdNamePKHRScanRange = "pkhrscanrange";

// PKHash
const std::string kCmdNamePKHSet = "pkhset";
const std::string kCmdNamePKHSetex = "pkhsetex";
const std::string kCmdNamePKHExpire = "pkhexpire";
const std::string kCmdNamePKHExpireat = "pkhexpireat";
const std::string kCmdNamePKHExpiretime = "pkhexpiretime";
Expand Down Expand Up @@ -312,7 +311,7 @@ enum CmdFlags {
kCmdFlagsStream = (1 << 20),
kCmdFlagsFast = (1 << 21),
kCmdFlagsSlow = (1 << 22),
kCmdFlagsPKHash = (1 << 23), // TODO(DDD)
kCmdFlagsPKHash = (1 << 23),
};

void inline RedisAppendContent(std::string& str, const std::string& value);
Expand Down
282 changes: 281 additions & 1 deletion include/pika_pkhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,290 @@ class PKHSetCmd : public Cmd {
Cmd* Clone() override { return new PKHSetCmd(*this); }

private:
// 每个命令的参数组成不同。
std::string key_, field_, value_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHSetexCmd : public Cmd {
public:
PKHSetexCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHSetexCmd(*this); }

private:
std::string key_, field_, value_;
int64_t sec_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHExistsCmd : public Cmd {
public:
PKHExistsCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHExistsCmd(*this); }

private:
std::string key_, field_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHDelCmd : public Cmd {
public:
PKHDelCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHDelCmd(*this); }

private:
std::string key_;
std::vector<std::string> fields_;
int32_t deleted_ = 0;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHLenCmd : public Cmd {
public:
PKHLenCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHLenCmd(*this); }

private:
std::string key_;
bool is_force_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHStrLenCmd : public Cmd {
public:
PKHStrLenCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHStrLenCmd(*this); }

private:
std::string key_, field_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHIncrbyCmd : public Cmd {
public:
PKHIncrbyCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHIncrbyCmd(*this); }

private:
std::string key_, field_;
int64_t by_;
int64_t sec_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHMSetCmd : public Cmd {
public:
PKHMSetCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHMSetCmd(*this); }

private:
std::string key_;
std::vector<storage::FieldValue> fvs_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHMGetCmd : public Cmd {
public:
PKHMGetCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHMGetCmd(*this); }

private:
std::string key_;
std::vector<std::string> fields_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHKeysCmd : public Cmd {
public:
PKHKeysCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHKeysCmd(*this); }

private:
std::string key_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHValsCmd : public Cmd {
public:
PKHValsCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHValsCmd(*this); }

private:
std::string key_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHGetAllCmd : public Cmd {
public:
PKHGetAllCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHGetAllCmd(*this); }

private:
std::string key_;
bool is_wt_;
void DoInitial() override;
rocksdb::Status s_;
};

class PKHScanCmd : public Cmd {
public:
PKHScanCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::PKHASH)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKHScanCmd(*this); }

private:
std::string key_, pattern_;
int64_t cursor_, count_;
bool is_wt_;
virtual void Clear() {
pattern_ = "*";
count_ = 10;
is_wt_ = false;
}

void DoInitial() override;
rocksdb::Status s_;
};

#endif
Loading

0 comments on commit 9d208a6

Please sign in to comment.