3 memcached_return
memcached_delete(memcached_st
*ptr
, char *key
, size_t key_length
,
6 return memcached_delete_by_key(ptr
, key
, key_length
,
7 key
, key_length
, expiration
);
10 memcached_return
memcached_delete_by_key(memcached_st
*ptr
,
11 char *master_key
, size_t master_key_length
,
12 char *key
, size_t key_length
,
17 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
18 unsigned int server_key
;
20 memcached_return rc
[MEMCACHED_MAX_REPLICAS
];
22 unlikely (key_length
== 0)
23 return MEMCACHED_NO_KEY_PROVIDED
;
25 unlikely (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
26 return MEMCACHED_NO_SERVERS
;
28 server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
31 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
32 "delete %.*s %llu\r\n", (int)key_length
, key
,
33 (unsigned long long)expiration
);
35 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
36 "delete %.*s\r\n", (int)key_length
, key
);
38 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
40 rc
[replicas
]= MEMCACHED_WRITE_FAILURE
;
44 to_write
= (ptr
->flags
& MEM_BUFFER_REQUESTS
) ? 0 : 1;
48 rc
[replicas
]= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, to_write
);
49 if (rc
[replicas
] != MEMCACHED_SUCCESS
)
52 if ((ptr
->flags
& MEM_BUFFER_REQUESTS
))
54 rc
[replicas
]= MEMCACHED_BUFFERED
;
58 rc
[replicas
]= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
59 if (rc
[replicas
] == MEMCACHED_DELETED
)
60 rc
[replicas
]= MEMCACHED_SUCCESS
;
63 /* On error we just jump to the next potential server */
65 if (replicas
> 1 && ptr
->distribution
== MEMCACHED_DISTRIBUTION_CONSISTENT
)
67 if (server_key
== (ptr
->number_of_hosts
- 1))
72 } while ((++replicas
) < ptr
->number_of_replicas
);
74 /* As long as one object gets stored, we count this as a success */
77 if (rc
[replicas
] == MEMCACHED_DELETED
)
78 return MEMCACHED_SUCCESS
;
79 else if (rc
[replicas
] == MEMCACHED_DELETED
)
80 rc
[replicas
]= MEMCACHED_BUFFERED
;