3 memcached_return
memcached_delete(memcached_st
*ptr
, char *key
, size_t key_length
,
7 size_t send_length
, sent_length
;
9 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
10 unsigned int server_key
;
12 LIBMEMCACHED_MEMCACHED_DELETE_START();
14 if (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
15 return MEMCACHED_NO_SERVERS
;
17 server_key
= memcached_generate_hash(ptr
, key
, key_length
);
19 if ((rc
= memcached_connect(ptr
, server_key
)) != MEMCACHED_SUCCESS
)
24 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
25 "delete %.*s %llu\r\n", (int)key_length
, key
,
26 (unsigned long long)expiration
);
28 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
29 "delete %.*s\r\n", (int)key_length
, key
);
31 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
33 rc
= MEMCACHED_WRITE_FAILURE
;
37 if ((ptr
->flags
& MEM_NO_BLOCK
))
42 if ((sent_length
= memcached_io_write(ptr
, server_key
, buffer
, send_length
, to_write
)) == -1)
44 memcached_quit_server(ptr
, server_key
);
45 rc
= MEMCACHED_WRITE_FAILURE
;
49 if ((ptr
->flags
& MEM_NO_BLOCK
))
51 rc
= MEMCACHED_SUCCESS
;
52 memcached_server_response_increment(ptr
, server_key
);
56 rc
= memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, server_key
);
57 if (rc
== MEMCACHED_DELETED
)
58 rc
= MEMCACHED_SUCCESS
;
61 LIBMEMCACHED_MEMCACHED_DELETE_END();