Skip to content

Commit

Permalink
INTERNAL: Remove dummy fetch in the get API
Browse files Browse the repository at this point in the history
  • Loading branch information
ing-eoking committed Jan 6, 2025
1 parent e31c51b commit a31b8bd
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions libmemcached/get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ char *memcached_get_by_key(memcached_st *ptr,
{
arcus_server_check_for_update(ptr);

if (value_length)
*value_length= 0;

if (flags)
*flags= 0;

memcached_return_t unused;
if (error == NULL)
error= &unused;
Expand All @@ -512,11 +518,6 @@ char *memcached_get_by_key(memcached_st *ptr,
*error= memcached_last_error(ptr);
}

if (value_length)
{
*value_length= 0;
}

return NULL;
}

Expand Down Expand Up @@ -549,20 +550,34 @@ char *memcached_get_by_key(memcached_st *ptr,
*error= memcached_last_error(ptr);
}

if (value_length)
*value_length= 0;

return NULL;
}

char *value= memcached_fetch(ptr, NULL, NULL,
value_length, flags, error);
char *value= NULL;
bool success_occurred= false;
memcached_result_st *result= &ptr->result;

while (memcached_fetch_result(ptr, result, error) != NULL)
{
success_occurred= true;
value= memcached_string_take_value(&result->value);
if (value_length)
*value_length= memcached_string_length(&result->value);
if (flags)
*flags= result->item_flags;
}

assert_msg(ptr->query_id >= query_id +1, "Programmer error, the query_id was not incremented.");
//assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");

/* This is for historical reasons */
if (*error == MEMCACHED_END)
if (success_occurred)
{
*error= MEMCACHED_SUCCESS;
}
else if (*error == MEMCACHED_END)
{
*error= MEMCACHED_NOTFOUND;
}

if (value == NULL)
{
Expand Down Expand Up @@ -616,18 +631,6 @@ char *memcached_get_by_key(memcached_st *ptr,
return NULL;
}

size_t dummy_length;
uint32_t dummy_flags;
memcached_return_t dummy_error;

char *dummy_value= memcached_fetch(ptr, NULL, NULL,
&dummy_length, &dummy_flags,
&dummy_error);
assert_msg(dummy_value == 0, "memcached_fetch() returned additional values beyond the single get it expected");
assert_msg(dummy_length == 0, "memcached_fetch() returned additional values beyond the single get it expected");
assert_msg(ptr->query_id >= query_id +1, "Programmer error, the query_id was not incremented.");
//assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");

return value;
}

Expand Down

0 comments on commit a31b8bd

Please sign in to comment.