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();
15 return MEMCACHED_NO_KEY_PROVIDED
;
17 if (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
18 return MEMCACHED_NO_SERVERS
;
20 server_key
= memcached_generate_hash(ptr
, key
, key_length
);
22 if ((rc
= memcached_connect(ptr
, server_key
)) != MEMCACHED_SUCCESS
)
27 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
28 "delete %.*s %llu\r\n", (int)key_length
, key
,
29 (unsigned long long)expiration
);
31 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
32 "delete %.*s\r\n", (int)key_length
, key
);
34 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
36 rc
= MEMCACHED_WRITE_FAILURE
;
40 if ((ptr
->flags
& MEM_NO_BLOCK
))
45 if ((sent_length
= memcached_io_write(ptr
, server_key
, buffer
, send_length
, to_write
)) == -1)
47 memcached_quit_server(ptr
, server_key
);
48 rc
= MEMCACHED_WRITE_FAILURE
;
52 if ((ptr
->flags
& MEM_NO_BLOCK
))
54 rc
= MEMCACHED_SUCCESS
;
55 memcached_server_response_increment(ptr
, server_key
);
59 rc
= memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, server_key
);
60 if (rc
== MEMCACHED_DELETED
)
61 rc
= MEMCACHED_SUCCESS
;
64 LIBMEMCACHED_MEMCACHED_DELETE_END();