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 rc
= memcached_validate_key_length(key_length
,
30 ptr
->flags
& MEM_BINARY_PROTOCOL
);
31 unlikely (rc
!= MEMCACHED_SUCCESS
)
34 unlikely (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
35 return MEMCACHED_NO_SERVERS
;
37 server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
38 to_write
= (ptr
->flags
& MEM_BUFFER_REQUESTS
) ? 0 : 1;
40 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
41 rc
= binary_delete(ptr
, server_key
, key
, key_length
, to_write
);
45 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
46 "delete %s%.*s %u\r\n",
49 (uint32_t)expiration
);
51 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
54 (int)key_length
, key
);
56 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
58 rc
= MEMCACHED_WRITE_FAILURE
;
62 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, to_write
);
65 if (rc
!= MEMCACHED_SUCCESS
)
68 if ((ptr
->flags
& MEM_BUFFER_REQUESTS
))
70 rc
= MEMCACHED_BUFFERED
;
74 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
75 if (rc
== MEMCACHED_DELETED
)
76 rc
= MEMCACHED_SUCCESS
;
79 if (rc
== MEMCACHED_SUCCESS
&& ptr
->delete_trigger
)
80 ptr
->delete_trigger(ptr
, key
, key_length
);
83 LIBMEMCACHED_MEMCACHED_DELETE_END();
87 static inline memcached_return
binary_delete(memcached_st
*ptr
,
88 unsigned int server_key
,
93 protocol_binary_request_delete request
= {.bytes
= {0}};
95 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
96 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_DELETE
;
97 request
.message
.header
.request
.keylen
= htons((uint16_t)key_length
);
98 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
99 request
.message
.header
.request
.bodylen
= htonl(key_length
);
101 if ((memcached_do(&ptr
->hosts
[server_key
], request
.bytes
,
102 sizeof(request
.bytes
), 0) != MEMCACHED_SUCCESS
) ||
103 (memcached_io_write(&ptr
->hosts
[server_key
], key
,
104 key_length
, flush
) == -1))
106 memcached_io_reset(&ptr
->hosts
[server_key
]);
107 return MEMCACHED_WRITE_FAILURE
;
110 return MEMCACHED_SUCCESS
;