memcache: support 'noreply' on 'set' and 'delete'

This commit is contained in:
Tomasz Grabiec
2014-10-16 17:59:30 +02:00
parent a1848ca6a7
commit f3ebe8abe9
2 changed files with 11 additions and 5 deletions

View File

@@ -45,9 +45,9 @@ blob := any+ >start_blob $advance_blob;
maybe_noreply = (sp "noreply" @{ _noreply = true; })? >{ _noreply = false; };
maybe_expiration = (sp expiration)? >{ _expiration = 0; };
set = "set" sp key sp flags sp expiration sp size (crlf @{ fcall blob; } ) crlf @{ _state = state::cmd_set; };
set = "set" sp key sp flags sp expiration sp size maybe_noreply (crlf @{ fcall blob; } ) crlf @{ _state = state::cmd_set; };
get = "get" (sp key %{ _keys.push_back(std::move(_key)); })+ crlf @{ _state = state::cmd_get; };
delete = "delete" sp key crlf @{ _state = state::cmd_delete; };
delete = "delete" sp key maybe_noreply crlf @{ _state = state::cmd_delete; };
flush = "flush_all" maybe_expiration maybe_noreply crlf @{ _state = state::cmd_flush_all; };
version = "version" crlf @{ _state = state::cmd_version; };
main := (set | get | delete | flush | version) >eof{ _state = state::eof; };

View File

@@ -250,6 +250,9 @@ public:
case memcache_ascii_parser::state::cmd_set:
_cache.set(std::move(_parser._key),
item_data{std::move(_parser._blob), _parser._flags, seconds_to_time_point(_parser._expiration)});
if (_parser._noreply) {
return make_ready_future<>();
}
return out.write(msg_stored);
case memcache_ascii_parser::state::cmd_get:
@@ -284,10 +287,13 @@ public:
}
case memcache_ascii_parser::state::cmd_delete:
if (_cache.remove(_parser._key)) {
return out.write(msg_deleted);
{
auto removed = _cache.remove(_parser._key);
if (_parser._noreply) {
return make_ready_future<>();
}
return out.write(msg_not_found);
return out.write(removed ? msg_deleted : msg_not_found);
}
case memcache_ascii_parser::state::cmd_flush_all:
if (_parser._expiration) {