2 We use this to dump all keys.
4 At this point we only support a callback method. This could be optimized by first
5 calling items and finding active slabs. For the moment though we just loop through
6 all slabs on servers and "grab" the keys.
10 static memcached_return
ascii_dump(memcached_st
*ptr
, memcached_dump_func
*callback
, void *context
, uint32_t number_of_callbacks
)
13 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
18 unlikely (ptr
->number_of_hosts
== 0)
19 return MEMCACHED_NO_SERVERS
;
21 for (server_key
= 0; server_key
< ptr
->number_of_hosts
; server_key
++)
23 /* 256 I BELIEVE is the upper limit of slabs */
24 for (x
= 0; x
< 256; x
++)
26 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
27 "stats cachedump %u 0 0\r\n", x
);
29 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, 1);
31 unlikely (rc
!= MEMCACHED_SUCCESS
)
36 uint32_t callback_counter
;
37 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
39 if (rc
== MEMCACHED_ITEM
)
41 char *string_ptr
, *end_ptr
;
45 string_ptr
+= 5; /* Move past ITEM */
46 for (end_ptr
= string_ptr
; isgraph(*end_ptr
); end_ptr
++);
48 key
[(size_t)(end_ptr
-string_ptr
)]= 0;
49 for (callback_counter
= 0; callback_counter
< number_of_callbacks
; callback_counter
++)
51 rc
= (*callback
[callback_counter
])(ptr
, key
, (size_t)(end_ptr
-string_ptr
), context
);
52 if (rc
!= MEMCACHED_SUCCESS
)
56 else if (rc
== MEMCACHED_END
)
65 if (rc
== MEMCACHED_END
)
66 return MEMCACHED_SUCCESS
;
71 memcached_return
memcached_dump(memcached_st
*ptr
, memcached_dump_func
*callback
, void *context
, uint32_t number_of_callbacks
)
73 /* No support for Binary protocol yet */
74 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
75 return MEMCACHED_FAILURE
;
77 return ascii_dump(ptr
, callback
, context
, number_of_callbacks
);