3 memcached_return
memcached_delete(memcached_st
*ptr
, const char *key
, size_t key_length
,
6 return memcached_delete_by_key(ptr
, key
, key_length
,
7 key
, key_length
, expiration
);
10 static inline memcached_return
binary_delete(memcached_st
*ptr
,
11 unsigned int server_key
,
16 memcached_return
memcached_delete_by_key(memcached_st
*ptr
,
17 const char *master_key
, size_t master_key_length
,
18 const char *key
, size_t key_length
,
24 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
25 unsigned int server_key
;
27 LIBMEMCACHED_MEMCACHED_DELETE_START();
29 unlikely (key_length
== 0)
30 return MEMCACHED_NO_KEY_PROVIDED
;
32 unlikely (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
33 return MEMCACHED_NO_SERVERS
;
35 server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
36 to_write
= (ptr
->flags
& MEM_BUFFER_REQUESTS
) ? 0 : 1;
38 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
39 rc
= binary_delete(ptr
, server_key
, key
, key_length
, to_write
);
43 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
44 "delete %s%.*s %llu\r\n",
47 (unsigned long long)expiration
);
49 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
52 (int)key_length
, key
);
54 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
56 rc
= MEMCACHED_WRITE_FAILURE
;
60 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, to_write
);
63 if (rc
!= MEMCACHED_SUCCESS
)
66 if ((ptr
->flags
& MEM_BUFFER_REQUESTS
))
68 rc
= MEMCACHED_BUFFERED
;
72 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
73 if (rc
== MEMCACHED_DELETED
)
74 rc
= MEMCACHED_SUCCESS
;
77 if (rc
== MEMCACHED_SUCCESS
&& ptr
->delete_trigger
)
78 ptr
->delete_trigger(ptr
, key
, key_length
);
81 LIBMEMCACHED_MEMCACHED_DELETE_END();
85 static inline memcached_return
binary_delete(memcached_st
*ptr
,
86 unsigned int server_key
,
91 protocol_binary_request_delete request
= {.bytes
= {0}};
93 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
94 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_DELETE
;
95 request
.message
.header
.request
.keylen
= htons((uint16_t)key_length
);
96 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
97 request
.message
.header
.request
.bodylen
= htonl(key_length
);
99 if ((memcached_do(&ptr
->hosts
[server_key
], request
.bytes
,
100 sizeof(request
.bytes
), 0) != MEMCACHED_SUCCESS
) ||
101 (memcached_io_write(&ptr
->hosts
[server_key
], key
,
102 key_length
, flush
) == -1))
104 memcached_io_reset(&ptr
->hosts
[server_key
]);
105 return MEMCACHED_WRITE_FAILURE
;
108 return MEMCACHED_SUCCESS
;