PHP solution for getting all keys
Hello,
I have run Membase in combination with PHP, but run into a problem I could not solve. Once a day, I want to read all keys that are currently in a Membase bucket, but I never truly found a descent answer to this.
First some background info:
Not long ago I was still running Memcached instead of Membase, and there was a simple, though effective way to read these keys in PHP (see below). Basicly I would use the statistics to get slab ids and using those, I would retrieve all items in in that slap to eventually go on until all keys were read.
Unfortunately this functionality broke when I updated to Membase 1.6.x or 1.7 resulting in me staying with Memcached. I really like to update to Membase, mostly because of the database behind it, but I will need a way to read all present keys in the Membase bucket.
I was wondering if there are already some solution that could do this. This solution does not have to be in PHP, as long as I could eventually write it to a file or import it into my PHP solution.
Anyone who could help me out here?
$list = array();
$all_slabs = $this->_Memcache->getExtendedStats('slabs');
foreach($all_slabs as $server => $slabs){
foreach(array_keys($slabs) as $slab_id){
$cdump = $this->_Memcache->getExtendedStats('cachedump', (int) $slab_id);
foreach($cdump as $keys => $values){
if(!is_array($values)) continue;
foreach($values as $key => $value){
if(empty($store) || substr($key, 0, strlen($store)) == $store){
if(empty($store)){
$list[] = $key;
}
else{
$list[] = substr($key, strlen($store) + 1);
}
}
}
}
}
}
return $list;Problem is that I only run Windows systems, so a linux solution is out of the question, and basically, I was looking for a solution that I could simply 'plug in'; a finished client that is able to get me those keys
Since I am very sure I am not the only one wanting something like this from Membase I hoped to find someone who does have this
One extra aspect of this is that python (like PHP) is cross-platform. Unlike linux systems, however, Windows doesn't come with python stuff pre-installed with the O/S. You can get Windows python installers, though, from http://python.org
If you like Java, too, there's Java class libraries that implement the TAP protocol. Please see: http://www.couchbase.org/
Cheers,
Steve
Frank Weigel also reminds me that I should mention that the TAP protocol works for Membase-type buckets. Support for TAP protocol for Memcached-type buckets, in contrast, is still a work-in-progress, and not certified.
Cheers,
Steve
Hi,
The most straightforward way to do this is via the TAP protocol. In 1.7 linux, there's an example script in...
/opt/membase/lib/python/tap_example.py
It should be possible to go from there to file or pipe, and then to PHP. Here's some more info on the TAP protocol details...
http://www.couchbase.org/wiki/display/membase/TAP+Protocol
Cheers,
Steve