Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixficsol committed Mar 29, 2024
2 parents 6e09141 + f3e09b8 commit 2d2a013
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 42 deletions.
9 changes: 8 additions & 1 deletion src/base_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const std::string kCmdNamePExpireat = "pexpireat";
const std::string kCmdNamePersist = "persist";
const std::string kCmdNameKeys = "keys";

const std::string kCmdNamePttl = "pttl";
// string cmd
const std::string kCmdNameSet = "set";
const std::string kCmdNameGet = "get";
Expand Down Expand Up @@ -120,8 +121,14 @@ const std::string kCmdNameLLen = "llen";
const std::string kCmdNameZAdd = "zadd";
const std::string kCmdNameZRevrange = "zrevrange";
const std::string kCmdNameZRangebyscore = "zrangebyscore";
const std::string kCmdNameZRevRangeByScore = "zrevrangebyscore";
const std::string kCmdNameZRemrangebyscore = "zremrangebyscore";
const std::string kCmdNameZRemrangebyrank = "zremrangebyrank";
const std::string kCmdNameZRevrangebyscore = "zrevrangebyscore";
const std::string kCmdNameZCard = "zcard";
const std::string kCmdNameZScore = "zscore";
const std::string kCmdNameZRange = "zrange";
const std::string kCmdNameZRangebylex = "zrangebylex";
const std::string kCmdNameZRevrangebylex = "zrevrangebylex";

enum CmdFlags {
kCmdFlagsWrite = (1 << 0), // May modify the dataset
Expand Down
55 changes: 55 additions & 0 deletions src/cmd_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,59 @@ void KeysCmd::DoCmd(PClient* client) {
}
}

PttlCmd::PttlCmd(const std::string& name, int16_t arity)
: BaseCmd(name, arity, kCmdFlagsReadonly, kAclCategoryRead | kAclCategoryKeyspace) {}

bool PttlCmd::DoInitial(PClient* client) {
client->SetKey(client->argv_[1]);
return true;
}

// like Blackwidow , Floyd still possible has same key in different data structure
void PttlCmd::DoCmd(PClient* client) {
std::map<storage::DataType, rocksdb::Status> type_status;
auto type_timestamp = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->TTL(client->Key(), &type_status);
for (const auto& item : type_timestamp) {
// mean operation exception errors happen in database
if (item.second == -3) {
client->SetRes(CmdRes::kErrOther, "ttl internal error");
return;
}
}
if (type_timestamp[storage::kStrings] != -2) {
if (type_timestamp[storage::kStrings] == -1) {
client->AppendInteger(-1);
} else {
client->AppendInteger(type_timestamp[storage::kStrings] * 1000);
}
} else if (type_timestamp[storage::kHashes] != -2) {
if (type_timestamp[storage::kHashes] == -1) {
client->AppendInteger(-1);
} else {
client->AppendInteger(type_timestamp[storage::kHashes] * 1000);
}
} else if (type_timestamp[storage::kLists] != -2) {
if (type_timestamp[storage::kLists] == -1) {
client->AppendInteger(-1);
} else {
client->AppendInteger(type_timestamp[storage::kLists] * 1000);
}
} else if (type_timestamp[storage::kSets] != -2) {
if (type_timestamp[storage::kSets] == -1) {
client->AppendInteger(-1);
} else {
client->AppendInteger(type_timestamp[storage::kSets] * 1000);
}
} else if (type_timestamp[storage::kZSets] != -2) {
if (type_timestamp[storage::kZSets] == -1) {
client->AppendInteger(-1);
} else {
client->AppendInteger(type_timestamp[storage::kZSets] * 1000);
}
} else {
// this key not exist
client->AppendInteger(-2);
}
}

} // namespace pikiwidb
12 changes: 12 additions & 0 deletions src/cmd_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,16 @@ class KeysCmd : public BaseCmd {
private:
void DoCmd(PClient* client) override;
};

class PttlCmd : public BaseCmd {
public:
PttlCmd(const std::string& name, int16_t arity);

protected:
bool DoInitial(PClient* client) override;

private:
void DoCmd(PClient* client) override;
};

} // namespace pikiwidb
9 changes: 8 additions & 1 deletion src/cmd_table_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void CmdTableManager::InitCmdTable() {
ADD_COMMAND(PExpire, 3);
ADD_COMMAND(Expireat, 3);
ADD_COMMAND(PExpireat, 3);
ADD_COMMAND(Pttl, 2);
ADD_COMMAND(Persist, 2);
ADD_COMMAND(Keys, 2);

Expand Down Expand Up @@ -127,8 +128,14 @@ void CmdTableManager::InitCmdTable() {
ADD_COMMAND(ZAdd, -4);
ADD_COMMAND(ZRevrange, -4);
ADD_COMMAND(ZRangebyscore, -4);
ADD_COMMAND(ZRevRangeByScore, -4);
ADD_COMMAND(ZRemrangebyscore, 4);
ADD_COMMAND(ZRemrangebyrank, 4);
ADD_COMMAND(ZRevrangebyscore, -4);
ADD_COMMAND(ZCard, 2);
ADD_COMMAND(ZScore, 3);
ADD_COMMAND(ZRange, -4);
ADD_COMMAND(ZRangebylex, -3);
ADD_COMMAND(ZRevrangebylex, -3);
}

std::pair<BaseCmd*, CmdRes::CmdRet> CmdTableManager::GetCommand(const std::string& cmdName, PClient* client) {
Expand Down
Loading

0 comments on commit 2d2a013

Please sign in to comment.