2014-04-05 42 views
3

我沒有在8091端口的couchbase admin UI中找到存儲桶的flush按鈕。可能是因爲這個http://www.couchbase.com/issues/browse/MB-5351在couchbase python客戶端中缺少flush方法嗎?

然後我看到這How to delete all items in the bucket?所以我想在Python客戶端做刷新。

import sys 
from couchbase import Couchbase 
from couchbase.exceptions import CouchbaseError 
try: 
    client = Couchbase.connect(bucket='production',host='localhost',port=8091) 
except CouchbaseError as e: 
    print " Sorry , we could not create connection to bucket specified , due to " , e 
else : 
    print "Successfully made the connection to bucket " 

這裏的客戶端我沒有找到刷新的方法。我在IDE中嘗試了intellisense。

請指導我通過python客戶端刷新存儲桶。

+0

在UI應該有使沖洗水桶的選項。你能確保這個無線電盒子被選中。 – mikewied

+0

'Flush'按鈕位於按鈕的* edit *對話框中;但是在出現之前需要啓用flush選項(也可以在* edit *對話框中)。 – DaveR

+0

雅我能看到沖水按鈕。謝謝 。但爲什麼沒有辦法從couchbase python客戶端刷新。 –

回答

1

看來,couchbase python SDK目前不提供flush()方法。 但由於flush方法是通過couchbase REST API提供的,因此您可以使用它來刷新存儲桶。

參考:Couchbase REST API,API桶 - http://docs.couchbase.com/admin/admin/REST/rest-bucket-intro.html

蟒蛇SDK提供了一個聯繫對象,您可以使用使用REST利用其HTTP_REQUEST方法來執行管理員任務。 源代碼:在管理類(從源)https://github.com/couchbase/couchbase-python-client/blob/master/couchbase/admin.py

描述:

到Couchbase集羣的管理連接。 (源文件)

With this object, you can do things which affect the cluster, such as 
modifying buckets, allocating nodes, or retrieving information about 
the cluster. 

This object should **not** be used to perform Key/Value operations. The 
:class:`couchbase.bucket.Bucket` is used for that. 

Admin.http_request方法說明:

Perform an administrative HTTP request. This request is sent out to 
    the administrative API interface (i.e. the "Management/REST API") 
    of the cluster. 

    See <LINK?> for a list of available comments. 

    Note that this is a fairly low level function. This class will with 
    time contain more and more wrapper methods for common tasks such 
    as bucket creation or node allocation, and this method should 
    mostly be used if a wrapper is not available. 

例子:

首先確保沖洗選項爲您激活桶。

我爲示例創建了一個名爲「default」的測試存儲桶,並在存儲桶中創建了2個文檔。

import sys 
from couchbase import Couchbase 
from couchbase.exceptions import CouchbaseError 

#import Admin module 
from couchbase.admin import Admin 


#make an administrative connection using Admin object 
try: 
    admin = Admin(username='Administrator',password='password',host='localhost',port=8091) 
except CouchbaseError as e: 
    print " Sorry , we could not create admin connection , due to " , e 
else : 
    print "Successfully made an admin connection " 


#retrieve bucket information for bucket named "default" 
# "default" is just the name of the bucket I set up for trying this out 
try: 
    htres = admin.http_request("/pools/default/buckets/default") 
except Exception as e: 
    print "ERROR: ", e 
    sys.exit() 


#print the current number of items in the "default" bucket 
# "default" is just the name of the bucket I set up for trying this out 
print "# of items before flush: ", htres.value['basicStats']['itemCount'] 


#flush bucket 
try: 
    #the bucket information request returned the path to the REST flush method for this bucket 
    # the flush method requires a POST request 
    htres = admin.http_request(htres.value['controllers']['flush'],"POST") 
except Exception as e: 
    print "ERROR: ", e 
    sys.exit() 


#re-retrieve bucket information for bucket named "default" 
try: 
    htres = admin.http_request("/pools/default/buckets/default") 
except Exception as e: 
    print "ERROR: ", e 
    sys.exit() 


#print the number of items in the "default" bucket (after flush) 
print "# of items after flush: ", htres.value['basicStats']['itemCount'] 

結果:

Successfully made an admin connection 
# of items before flush: 2 
# of items after flush: 0 
+0

這可能會起作用,但那些無法訪問管理員密碼的代碼呢? (這就是爲什麼我一開始就在尋找一種使用Python SDK的方法)。 –

+2

似乎自去年以來有一個公開的問題。 HTTPS://issues.couchbase。com/browse/PYCBC-214 – Unknown

+0

@JohnC不幸的是,當我遇到上述解決方案時,我停止了尋找。在閱讀您的評論之後,我確實嘗試了用戶名= None和密碼= None,並且仍然能夠連接並按默認設置刷新存儲桶(儘管我沒有花時間弄清楚爲什麼它允許我這樣做。 ..這可能是你可以進一步研究的東西)。 – KorreyD

相關問題