3 static memcached_return_t
memcached_flush_binary(memcached_st
*ptr
,
5 static memcached_return_t
memcached_flush_textual(memcached_st
*ptr
,
8 memcached_return_t
memcached_flush(memcached_st
*ptr
, time_t expiration
)
10 memcached_return_t rc
;
12 LIBMEMCACHED_MEMCACHED_FLUSH_START();
13 if (ptr
->flags
.binary_protocol
)
14 rc
= memcached_flush_binary(ptr
, expiration
);
16 rc
= memcached_flush_textual(ptr
, expiration
);
17 LIBMEMCACHED_MEMCACHED_FLUSH_END();
21 static memcached_return_t
memcached_flush_textual(memcached_st
*ptr
,
26 memcached_return_t rc
;
27 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
29 unlikely (memcached_server_count(ptr
) == 0)
30 return MEMCACHED_NO_SERVERS
;
32 for (x
= 0; x
< memcached_server_count(ptr
); x
++)
34 bool no_reply
= ptr
->flags
.no_reply
;
35 memcached_server_instance_st
*instance
=
36 memcached_server_instance_fetch(ptr
, x
);
39 send_length
= (size_t) snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
40 "flush_all %llu%s\r\n",
41 (unsigned long long)expiration
, no_reply
? " noreply" : "");
43 send_length
= (size_t) snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
44 "flush_all%s\r\n", no_reply
? " noreply" : "");
46 rc
= memcached_do(instance
, buffer
, send_length
, 1);
48 if (rc
== MEMCACHED_SUCCESS
&& !no_reply
)
49 (void)memcached_response(instance
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
52 return MEMCACHED_SUCCESS
;
55 static memcached_return_t
memcached_flush_binary(memcached_st
*ptr
,
59 protocol_binary_request_flush request
= {.bytes
= {0}};
61 unlikely (memcached_server_count(ptr
) == 0)
62 return MEMCACHED_NO_SERVERS
;
64 request
.message
.header
.request
.magic
= (uint8_t)PROTOCOL_BINARY_REQ
;
65 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
66 request
.message
.header
.request
.extlen
= 4;
67 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
68 request
.message
.header
.request
.bodylen
= htonl(request
.message
.header
.request
.extlen
);
69 request
.message
.body
.expiration
= htonl((uint32_t) expiration
);
71 for (x
= 0; x
< memcached_server_count(ptr
); x
++)
73 memcached_server_instance_st
*instance
=
74 memcached_server_instance_fetch(ptr
, x
);
76 if (ptr
->flags
.no_reply
)
78 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSHQ
;
82 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_FLUSH
;
85 if (memcached_do(instance
, request
.bytes
,
86 sizeof(request
.bytes
), 1) != MEMCACHED_SUCCESS
)
88 memcached_io_reset(instance
);
89 return MEMCACHED_WRITE_FAILURE
;
93 for (x
= 0; x
< memcached_server_count(ptr
); x
++)
95 memcached_server_instance_st
*instance
=
96 memcached_server_instance_fetch(ptr
, x
);
98 if (memcached_server_response_count(instance
) > 0)
99 (void)memcached_response(instance
, NULL
, 0, NULL
);
102 return MEMCACHED_SUCCESS
;