8
8
key, key_length, expiration);
11
static inline memcached_return binary_delete(memcached_st *ptr,
12
unsigned int server_key,
17
11
memcached_return memcached_delete_by_key(memcached_st *ptr,
18
const char *master_key, size_t master_key_length,
19
const char *key, size_t key_length,
12
const char *master_key,
13
size_t master_key_length,
19
return MEMCACHED_INVALID_ARGUMENTS;
24
21
memcached_return rc;
25
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
26
22
unsigned int server_key;
28
24
LIBMEMCACHED_MEMCACHED_DELETE_START();
30
rc= memcached_validate_key_length(key_length,
31
ptr->flags & MEM_BINARY_PROTOCOL);
32
unlikely (rc != MEMCACHED_SUCCESS)
35
26
unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
36
27
return MEMCACHED_NO_SERVERS;
38
29
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
39
to_write= (uint8_t)((ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1);
40
bool no_reply= (ptr->flags & MEM_NOREPLY);
42
if (ptr->flags & MEM_BINARY_PROTOCOL)
45
rc= binary_delete(ptr, server_key, key, key_length, to_write);
47
rc= MEMCACHED_INVALID_ARGUMENTS;
53
if ((ptr->hosts[server_key].major_version == 1 &&
54
ptr->hosts[server_key].minor_version > 2) ||
55
ptr->hosts[server_key].major_version > 1)
57
rc= MEMCACHED_INVALID_ARGUMENTS;
62
if (ptr->hosts[server_key].minor_version == 0)
64
if (no_reply || !to_write)
66
/* We might get out of sync with the server if we
67
* send this command to a server newer than 1.2.x..
68
* disable no_reply and buffered mode.
72
memcached_server_response_increment(&ptr->hosts[server_key]);
76
send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
77
"delete %s%.*s %u%s\r\n",
79
(int) key_length, key,
81
no_reply ? " noreply" :"" );
85
send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
86
"delete %s%.*s%s\r\n",
88
(int)key_length, key, no_reply ? " noreply" :"");
90
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
92
rc= MEMCACHED_WRITE_FAILURE;
96
if (ptr->flags & MEM_USE_UDP && !to_write)
98
if (send_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
99
return MEMCACHED_WRITE_FAILURE;
100
if (send_length + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
101
memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
104
rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
107
if (rc != MEMCACHED_SUCCESS)
111
rc= MEMCACHED_BUFFERED;
114
rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
115
if (rc == MEMCACHED_DELETED)
116
rc= MEMCACHED_SUCCESS;
30
rc= ptr->protocol_hooks->delete(ptr, server_key, key, key_length);
119
31
if (rc == MEMCACHED_SUCCESS && ptr->delete_trigger)
120
32
ptr->delete_trigger(ptr, key, key_length);
123
34
LIBMEMCACHED_MEMCACHED_DELETE_END();
127
38
static inline memcached_return binary_delete(memcached_st *ptr,
128
39
unsigned int server_key,
133
protocol_binary_request_delete request= {.bytes= {0}};
135
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
136
if (ptr->flags & MEM_NOREPLY)
137
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ;
139
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE;
140
request.message.header.request.keylen= htons((uint16_t)key_length);
141
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
142
request.message.header.request.bodylen= htonl((uint32_t) key_length);
44
protocol_binary_request_delete request= {
45
.message.header.request= {
46
.magic= PROTOCOL_BINARY_REQ,
47
.opcode= (ptr->flags & MEM_NOREPLY) ? PROTOCOL_BINARY_CMD_DELETEQ :
48
PROTOCOL_BINARY_CMD_DELETE,
49
.keylen= htons((uint16_t)key_length),
50
.datatype= PROTOCOL_BINARY_RAW_BYTES,
51
.bodylen= htonl((uint32_t) key_length)
144
55
if (ptr->flags & MEM_USE_UDP && !flush)
98
memcached_return memcached_binary_delete(memcached_st *ptr,
99
unsigned int server_key,
103
memcached_return rc= memcached_validate_key_length(key_length, true);
104
unlikely (rc != MEMCACHED_SUCCESS)
106
uint8_t to_write= (uint8_t)((ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1);
107
bool no_reply= (ptr->flags & MEM_NOREPLY);
109
rc= binary_delete(ptr, server_key, key, key_length, to_write);
110
if (rc == MEMCACHED_SUCCESS)
112
if ((ptr->flags & MEM_BUFFER_REQUESTS))
113
rc= MEMCACHED_BUFFERED;
116
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
117
rc= memcached_response(&ptr->hosts[server_key], buffer,
118
sizeof(buffer), NULL);
119
if (rc == MEMCACHED_DELETED)
120
rc= MEMCACHED_SUCCESS;
127
memcached_return memcached_internal_delete(memcached_st *ptr,
128
unsigned int server_key,
133
memcached_return rc= memcached_validate_key_length(key_length, false);
134
unlikely (rc != MEMCACHED_SUCCESS)
137
return internal_delete(ptr, key, key_length);
141
memcached_return memcached_ascii_delete(memcached_st *ptr,
142
unsigned int server_key,
146
memcached_return rc= memcached_validate_key_length(key_length, false);
147
unlikely (rc != MEMCACHED_SUCCESS)
150
uint8_t to_write= (uint8_t)((ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1);
151
bool no_reply= (ptr->flags & MEM_NOREPLY);
152
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
153
size_t send_length= (size_t) snprintf(buffer, sizeof(buffer),
154
"delete %s%.*s%s\r\n",
156
(int)key_length, key,
157
no_reply ? " noreply" :"");
159
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
161
rc= MEMCACHED_WRITE_FAILURE;
165
if (ptr->flags & MEM_USE_UDP && !to_write)
167
if (send_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
169
return MEMCACHED_WRITE_FAILURE;
172
if (send_length + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
174
memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
178
rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
180
if (rc != MEMCACHED_SUCCESS)
184
rc= MEMCACHED_BUFFERED;
187
rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
188
if (rc == MEMCACHED_DELETED)
189
rc= MEMCACHED_SUCCESS;
192
if (rc == MEMCACHED_SUCCESS && ptr->delete_trigger)
193
ptr->delete_trigger(ptr, key, key_length);
196
LIBMEMCACHED_MEMCACHED_DELETE_END();