Skip to content

Commit

Permalink
feat naver#487 - implement process_touch_command
Browse files Browse the repository at this point in the history
alter expire time without fetch item
  • Loading branch information
cheesecrust committed Jul 5, 2024
1 parent d5f6c56 commit b0fcd32
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -13089,20 +13089,56 @@ static void process_touch_command(conn *c, token_t *tokens, const size_t ntokens
{
assert(c != NULL);
assert(c->ewouldblock == false);
char *key = tokens[KEY_TOKEN].value;
size_t nkey = tokens[KEY_TOKEN].length;

if (nkey > KEY_MAX_LENGTH) {
char *key = tokens[KEY_TOKEN].value;
size_t nkey = tokens[KEY_TOKEN].length;

ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
item_attr attr_data;
int64_t exptime=0;
ENGINE_ITEM_ATTR attr_ids[ATTR_END];
uint32_t attr_count = 0;

if ((! safe_strtoll(tokens[KEY_TOKEN+1].value, &exptime)))
{
print_invalid_command(c, tokens, ntokens);
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
}

attr_data.exptime = exptime;
attr_ids[attr_count++] = ATTR_EXPIRETIME;

if (ret == ENGINE_SUCCESS) {
ret = mc_engine.v1->setattr(mc_engine.v0, c, key, nkey,
attr_ids, attr_count, &attr_data, 0);
CONN_CHECK_AND_SET_EWOULDBLOCK(ret, c);
if (settings.detail_enabled) {
stats_prefix_record_setattr(key, nkey);
}
}

switch (ret) {
case ENGINE_SUCCESS:
STATS_HITS(c, setattr, key, nkey);
out_string(c, "OK");
break;
case ENGINE_KEY_ENOENT:
STATS_MISSES(c, setattr, key, nkey);
out_string(c, "NOT_FOUND");
break;
default:
STATS_CMD_NOKEY(c, setattr);
if (ret == ENGINE_EBADATTR) out_string(c, "ATTR_ERROR not found");
else if (ret == ENGINE_EBADVALUE) out_string(c, "ATTR_ERROR bad value");
else handle_unexpected_errorcode_ascii(c, __func__, ret);
}

out_string(c, "hi touch!!")
}

static void process_command_ascii(conn *c, char *command, int cmdlen)
{
/* One more token is reserved in tokens strucure
/* One more token is reserved in tokens structure
* for keeping the length of untokenized command.
*/
token_t tokens[MAX_TOKENS+1];
Expand Down Expand Up @@ -13221,7 +13257,7 @@ static void process_command_ascii(conn *c, char *command, int cmdlen)
{
process_config_command(c, tokens, ntokens);
}
else if ((ntokens >= 0) && (strcmp(tokens[COMMAND_TOKEN].value, "touch") == 0))
else if ((ntokens == 4) && (strcmp(tokens[COMMAND_TOKEN].value, "touch") == 0))
{
process_touch_command(c, tokens, ntokens);
}
Expand Down

0 comments on commit b0fcd32

Please sign in to comment.