提交 87398f5c 编写于 作者: S songzhao

add persist

上级 476b6f2d
......@@ -141,6 +141,12 @@ public:
virtual void Do(std::list<std::string> &argvs, std::string &ret);
};
class PersistCmd : public Cmd {
public:
PersistCmd(int a) : Cmd(a) {};
virtual void Do(std::list<std::string> &argvs, std::string &ret);
};
class ScanCmd : public Cmd {
public:
ScanCmd(int a) : Cmd(a) {};
......
......@@ -161,6 +161,8 @@ int main(int argc, char **argv)
g_pikaCmd.insert(std::pair<std::string, Cmd *>("expireat", expireatptr));
TtlCmd *ttlptr = new TtlCmd(2);
g_pikaCmd.insert(std::pair<std::string, Cmd *>("ttl", ttlptr));
PersistCmd *persistptr = new PersistCmd(2);
g_pikaCmd.insert(std::pair<std::string, Cmd *>("persist", persistptr));
ScanCmd *scanptr = new ScanCmd(-2);
g_pikaCmd.insert(std::pair<std::string, Cmd *>("scan", scanptr));
......
......@@ -648,6 +648,29 @@ void TtlCmd::Do(std::list<std::string> &argv, std::string &ret) {
}
}
void PersistCmd::Do(std::list<std::string> &argv, std::string &ret) {
if ((arity > 0 && (int)argv.size() != arity) || (arity < 0 && (int)argv.size() < -arity)) {
ret = "-ERR wrong number of arguments for ";
ret.append(argv.front());
ret.append(" command\r\n");
return;
}
argv.pop_front();
std::string key = argv.front();
argv.pop_front();
int64_t res;
nemo::Status s = g_pikaServer->GetHandle()->Persist(key, &res);
if (s.ok() || s.IsNotFound()) {
char buf[32];
snprintf(buf, sizeof(buf), ":%ld\r\n", res);
ret.append(buf);
} else {
ret.append("-ERR ");
ret.append(s.ToString().c_str());
ret.append("\r\n");
}
}
void ScanCmd::Do(std::list<std::string> &argv, std::string &ret) {
int size = argv.size();
if ((arity > 0 && (int)argv.size() != arity) || (arity < 0 && (int)argv.size() < -arity) || (size != 2 && size != 4 && size != 6)) {
......
Subproject commit 973203ed5a76e8d24dd103c7429b6ad777cdca4a
Subproject commit 197ae5c0a0b46ac5afb1fc23c912966b93d48337
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册