3 memcached_return
memcached_delete(memcached_st
*ptr
, char *key
, size_t key_length
,
6 size_t send_length
, sent_length
;
8 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
9 unsigned int server_key
;
11 rc
= memcached_connect(ptr
);
13 if (rc
!= MEMCACHED_SUCCESS
)
16 server_key
= memcached_generate_hash(key
, key_length
) % ptr
->number_of_hosts
;
19 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
20 "delete %.*s %llu\r\n", (int)key_length
, key
,
21 (unsigned long long)expiration
);
23 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
24 "delete %.*s\r\n", (int)key_length
, key
);
26 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
27 return MEMCACHED_WRITE_FAILURE
;
29 sent_length
= write(ptr
->hosts
[server_key
].fd
, buffer
, send_length
);
31 if (sent_length
== -1 || sent_length
!= send_length
)
32 return MEMCACHED_WRITE_FAILURE
;
34 return memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, server_key
);