Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Membase | Membase Server 1.7.x

PHP solution for getting all keys

4 replies [Last post]
  • Login or register to post comments
Fri, 06/24/2011 - 04:52
braaibander
Offline
Joined: 06/24/2011
Groups: None

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;

Top
  • Login or register to post comments
Fri, 06/24/2011 - 08:32
steve
Offline
Joined: 03/15/2010
Groups: None

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

Top
  • Login or register to post comments
Mon, 06/27/2011 - 01:10
braaibander
Offline
Joined: 06/24/2011
Groups: None

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

Top
  • Login or register to post comments
Mon, 06/27/2011 - 11:02
steve
Offline
Joined: 03/15/2010
Groups: None

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

Top
  • Login or register to post comments
Mon, 06/27/2011 - 20:35
steve
Offline
Joined: 03/15/2010
Groups: None

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

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker