Add memcached version and delete commands
This commit is contained in:
parent
edf74d2494
commit
3f7e3a5a0a
|
@ -130,11 +130,11 @@ a distributed log format.
|
|||
- [X] stats (partial)
|
||||
- [x] append
|
||||
- [x] prepend
|
||||
- [ ] delete
|
||||
- [x] delete
|
||||
- [ ] flush_all
|
||||
- [x] incr
|
||||
- [x] decr
|
||||
- [ ] version
|
||||
- [x] version
|
||||
- [x] quit
|
||||
|
||||
API 2.0
|
||||
|
|
2
helio
2
helio
|
@ -1 +1 @@
|
|||
Subproject commit 1b01326ec8689e559dcf4c5be6f328055479e808
|
||||
Subproject commit 775f321d8efe9b90fae3fee14b2fcf8364beae7b
|
|
@ -160,6 +160,8 @@ void GenericFamily::Del(CmdArgList args, ConnectionContext* cntx) {
|
|||
VLOG(1) << "Del " << ArgS(args, 1);
|
||||
|
||||
atomic_uint32_t result{0};
|
||||
bool is_mc = cntx->protocol() == Protocol::MEMCACHE;
|
||||
|
||||
auto cb = [&result](const Transaction* t, EngineShard* shard) {
|
||||
ArgSlice args = t->ShardArgsInShard(shard->shard_id());
|
||||
auto res = OpDel(OpArgs{shard, t->db_index()}, args);
|
||||
|
@ -173,7 +175,18 @@ void GenericFamily::Del(CmdArgList args, ConnectionContext* cntx) {
|
|||
|
||||
DVLOG(2) << "Del ts " << transaction->txid();
|
||||
|
||||
(*cntx)->SendLong(result.load(memory_order_release));
|
||||
uint32_t del_cnt = result.load(memory_order_relaxed);
|
||||
if (is_mc) {
|
||||
MCReplyBuilder* mc_builder = static_cast<MCReplyBuilder*>(cntx->reply_builder());
|
||||
|
||||
if (del_cnt == 0) {
|
||||
mc_builder->SendNotFound();
|
||||
} else {
|
||||
mc_builder->SendDirect("DELETED\r\n");
|
||||
}
|
||||
} else {
|
||||
(*cntx)->SendLong(del_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
void GenericFamily::Ping(CmdArgList args, ConnectionContext* cntx) {
|
||||
|
|
|
@ -489,6 +489,9 @@ void Service::DispatchMC(const MemcacheParser::Command& cmd, std::string_view va
|
|||
strcpy(cmd_name, "SET");
|
||||
strcpy(store_opt, "NX");
|
||||
break;
|
||||
case MemcacheParser::DELETE:
|
||||
strcpy(cmd_name, "DEL");
|
||||
break;
|
||||
case MemcacheParser::INCR:
|
||||
strcpy(cmd_name, "INCRBY");
|
||||
absl::numbers_internal::FastIntToBuffer(cmd.delta, store_opt);
|
||||
|
@ -512,7 +515,9 @@ void Service::DispatchMC(const MemcacheParser::Command& cmd, std::string_view va
|
|||
case MemcacheParser::STATS:
|
||||
server_family_.StatsMC(cmd.key, cntx);
|
||||
return;
|
||||
|
||||
case MemcacheParser::VERSION:
|
||||
mc_builder->SendDirect(absl::StrCat("VERSION ", gflags::VersionString(), "\r\n"));
|
||||
return;
|
||||
default:
|
||||
mc_builder->SendClientError("bad command line format");
|
||||
return;
|
||||
|
|
|
@ -22,7 +22,7 @@ MP::CmdType From(string_view token) {
|
|||
{"get", MP::GET}, {"gets", MP::GETS}, {"gat", MP::GAT},
|
||||
{"gats", MP::GATS}, {"stats", MP::STATS}, {"incr", MP::INCR},
|
||||
{"decr", MP::DECR}, {"delete", MP::DELETE}, {"flush_all", MP::FLUSHALL},
|
||||
{"quit", MP::QUIT},
|
||||
{"quit", MP::QUIT}, {"version", MP::VERSION},
|
||||
};
|
||||
|
||||
auto it = cmd_map.find(token);
|
||||
|
@ -165,7 +165,7 @@ auto MP::Parse(string_view str, uint32_t* consumed, Command* cmd) -> Result {
|
|||
}
|
||||
|
||||
if (num_tokens == 1) {
|
||||
if (base::_in(cmd->type, {MP::STATS, MP::FLUSHALL, MP::QUIT}))
|
||||
if (base::_in(cmd->type, {MP::STATS, MP::FLUSHALL, MP::QUIT, MP::VERSION}))
|
||||
return MP::OK;
|
||||
return MP::PARSE_ERROR;
|
||||
}
|
||||
|
|
|
@ -31,12 +31,13 @@ class MemcacheParser {
|
|||
STATS = 14,
|
||||
|
||||
QUIT = 20,
|
||||
VERSION = 21,
|
||||
|
||||
// The rest of write commands.
|
||||
DELETE = 21,
|
||||
INCR = 22,
|
||||
DECR = 23,
|
||||
FLUSHALL = 24,
|
||||
DELETE = 31,
|
||||
INCR = 32,
|
||||
DECR = 33,
|
||||
FLUSHALL = 34,
|
||||
};
|
||||
|
||||
// According to https://github.com/memcached/memcached/wiki/Commands#standard-protocol
|
||||
|
|
Loading…
Reference in New Issue