本文整理汇总了Python中couchbase.bucket.Bucket类的典型用法代码示例。如果您正苦于以下问题:Python Bucket类的具体用法?Python Bucket怎么用?Python Bucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bucket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createView
def _createView(self, designDocument, viewName, mapFunction, reduceFunction):
bucket = Bucket(self._bucketUrl)
if reduceFunction == None:
designDocument["views"][viewName] = {"map": mapFunction}
else:
designDocument["views"][viewName] = {"map": mapFunction, "reduce": reduceFunction}
bucket.design_create(self.designDocumentName, designDocument, False, 10000)
示例2: get
def get(self, id):
bucket = Bucket(self._bucketUrl)
try:
result = bucket.get(id)
return result.value
except NotFoundError:
return None
示例3: confirm_ir
def confirm_ir(request, ir_id, group_id, user_id):
print("IR CONFIRMATION")
c = Bucket('couchbase://localhost/nihongo')
user_doc = c.get(user_id).value
password = user_doc['password']
ir_doc = c.get(ir_id).value
if 'accept' in request.POST:
print("IR ACCEPTED")
ir_doc['confirmed'] = 'accepted'
sync_user = SyncGateway.get_user(user_id)
new_sync_user = {}
admin_channels = sync_user['admin_channels']
#all_channels = sync_user['all_channels']
admin_channels.append(group_id)
SyncGateway.put_user(sync_user['name'], '[email protected]', password, admin_channels)
print(sync_user)
elif 'decline' in request.POST:
ir_doc['confirmed'] = 'declined'
print("IR DECLINED")
c.upsert(ir_id, ir_doc)
return HttpResponseRedirect(reverse('tutor:tutor_groups'))
示例4: parseAndSave
def parseAndSave(s):
for l in s.find (id="data_list").findAll("tr"):
try:
tagALinkToDetail = l.find(has_link_to_show_php)
if tagALinkToDetail:
fullText=tagALinkToDetail.text.strip()
logger.info("Searching info in douban with keyword: %s" % fullText)
m = Movie(fullText)
m.source_link = tagALinkToDetail['href']
m.numberOfSeeds=int(tagALinkToDetail.parent.parent.find(class_='bts_1').text)
m.source_link=str(tagALinkToDetail["href"])
bucket = Bucket('couchbase://localhost/default')
v=json.dumps(m.__dict__)
bucket.upsert(fullText,v)
else:
logger.debug("skip a line in mp4ba resource page, most likely because it is an ads")
except AttributeError as ae:
logger.error (ae)
logger.error ("Error! Skipped when trying to parse: %s" % l)
exit
except Exception as e:
logger.error (e)
logger.error ("Error! Skipped when trying to parse: %s" % l)
exit
示例5: register
def register(request):
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
if request.POST:
newuser_form = UserCreationForm(request.POST)
if newuser_form.is_valid():
newuser_form.save()
newuser = auth.authenticate(username=newuser_form.cleaned_data['username'], password=newuser_form.cleaned_data['password2'])
auth.login(request, newuser)
#Adding user to main bucket
try:
c = Bucket('couchbase://localhost/nihongo')
username = newuser_form.cleaned_data['username']
password = newuser_form.cleaned_data['password2']
c_username = 'user_' + username
new_user = {'username' : username, 'password' : password, 'doc_type' : 'user_doc'}
doc_channels = [c_username]
new_user['doc_channels'] = doc_channels
c.upsert(c_username, new_user)
except CouchbaseError as ce:
raise Http404("Couchbase server error")
#Adding user to sync gateway database
SyncGateway.put_user(c_username, '[email protected]', password, [c_username])
return redirect('/')
else:
args['form'] = newuser_form
return render_to_response('register.html', args)
示例6: get
def get(self,device_id):
bucket = Bucket('couchbase://46.101.11.33:8091/devices')
res = bucket.get(device_id, quiet=True)
if res.success:
return res.value
else:
return {"errCode": "-1", "errMsg": "Could not find device %s" % device_id}
示例7: _update_document
def _update_document(self, key, document):
url = 'couchbase://{ip}/default'.format(ip=self.master.ip)
if self.upgrade_to.startswith("4"):
bucket = Bucket(url)
else:
bucket = Bucket(url, username="default", password="password")
bucket.upsert(key, document)
示例8: test_function_where_handler_code_takes_more_time_to_execute_than_execution_timeout
def test_function_where_handler_code_takes_more_time_to_execute_than_execution_timeout(self):
keys = ['customer123', 'customer1234', 'customer12345']
url = 'couchbase://{ip}/{name}'.format(ip=self.master.ip, name=self.src_bucket_name)
bucket = Bucket(url, username="cbadminbucket", password="password")
for doc_id in keys:
bucket.upsert(doc_id, {'name' : doc_id})
# create a function which sleeps for 5 secs and set execution_timeout to 1s
body = self.create_save_function_body(self.function_name, HANDLER_CODE_ERROR.EXECUTION_TIME_MORE_THAN_TIMEOUT,
execution_timeout=1)
# deploy the function
self.deploy_function(body)
# This is intentionally added so that we wait for some mutations to process and we decide none are processed
self.sleep(60)
# No docs should be present in dst_bucket as the all the function executions should have timed out
self.verify_eventing_results(self.function_name, 0, skip_stats_validation=True)
eventing_nodes = self.get_nodes_from_services_map(service_type="eventing", get_all_nodes=True)
exec_timeout_count = 0
for eventing_node in eventing_nodes:
rest_conn = RestConnection(eventing_node)
out = rest_conn.get_all_eventing_stats()
# get sum of all timeout_count
exec_timeout_count += out[0]["failure_stats"]["timeout_count"]
# check whether all the function executions timed out and is equal to number of docs created
if exec_timeout_count != len(keys):
self.fail("Not all event executions timed out : Expected : {0} Actual : {1}".format(len(keys),
exec_timeout_count))
self.undeploy_and_delete_function(body)
示例9: test_add_concurrent
def test_add_concurrent(self):
DOCID = 'subdoc_doc_id'
CONNSTR = 'couchbase://' + self.servers[0].ip + ':11210'
ITERATIONS = 200
THREADS = 20
main_bucket = SDK_Bucket(CONNSTR)
main_bucket.upsert(DOCID, {'recs':[]})
thrs = []
class Runner(Thread):
def run(self, *args, **kw):
cb = SDK_Bucket(CONNSTR)
for x in range(ITERATIONS):
cb.mutate_in(DOCID, SD.array_append('recs', 1))
thrs = [Runner() for x in range(THREADS)]
[t.start() for t in thrs]
[t.join() for t in thrs]
obj = main_bucket.get(DOCID)
array_entry_count = len(obj.value['recs'])
self.assertTrue( array_entry_count == ITERATIONS * THREADS,
'Incorrect number of array entries. Expected {0} actual {1}'.format(ITERATIONS * THREADS,
array_entry_count))
示例10: check_dataloss
def check_dataloss(self, server, bucket):
from couchbase.bucket import Bucket
from couchbase.exceptions import NotFoundError
from lib.memcached.helper.data_helper import VBucketAwareMemcached
bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name))
rest = RestConnection(self.master)
VBucketAware = VBucketAwareMemcached(rest, bucket.name)
_, _, _ = VBucketAware.request_map(rest, bucket.name)
batch_start = 0
batch_end = 0
batch_size = 10000
errors = []
while self.num_items > batch_end:
batch_end = batch_start + batch_size
keys = []
for i in xrange(batch_start, batch_end, 1):
keys.append(str(i).rjust(20, '0'))
try:
bkt.get_multi(keys)
self.log.info("Able to fetch keys starting from {0} to {1}".format(keys[0], keys[len(keys)-1]))
except Exception as e:
self.log.error(e)
self.log.info("Now trying keys in the batch one at a time...")
key = ''
try:
for key in keys:
bkt.get(key)
except NotFoundError:
vBucketId = VBucketAware._get_vBucket_id(key)
errors.append("Missing key: {0}, VBucketId: {1}".
format(key, vBucketId))
batch_start += batch_size
return errors
示例11: main
def main():
from argparse import ArgumentParser
import time
ap = ArgumentParser()
ap.add_argument('-C', '--couchbase',
help='Couchbase connection string',
default='couchbase://localhost')
ap.add_argument('-M', '--memcached',
help='List of memcached hosts to use in host:port format',
action='append',
default=[])
options = ap.parse_args()
# Get memcached hosts
mc_hosts = []
for server in options.memcached:
host, port = server.split(':')
port = int(port)
mc_hosts.append((host, port))
mirror = CouchbaseMemcacheMirror(options.couchbase, mc_hosts)
value = {
'entry': 'Mirror value',
'updated': time.time()
}
mirror.set('mirrkey', value)
# Create individual clients, to demonstrate
cb = CbBucket(options.couchbase)
print 'Value from couchbase: {}'.format(cb.get('mirrkey').value)
print 'Value from Memcached: {}'.format(McClient(mc_hosts).get('mirrkey'))
开发者ID:couchbaselabs,项目名称:sk-python-couchbase-memcache-mirror,代码行数:32,代码来源:couchbase_memcache_mirror.py
示例12: get_phrases
def get_phrases(self, cb_url, output_file, input_file, docs_total):
cb = Bucket("couchbase://{}/{}?operation_timeout=10".format(cb_url, "bucket-1"), password="password")
lines = self._shuffle_and_cut(input_file, 10 ** 6)
formatted_lines = list()
for line in lines:
formatted_lines.append(line.split()[0])
lines = formatted_lines
results = set()
for docid in range(1, docs_total - 1):
key = hex(random.randint(1, docs_total))[2:]
try:
txt = cb.get(key).value
if txt["text"]:
txt = txt["text"].encode('ascii', 'ignore')
terms = txt.split(' ')
for idx, term in enumerate(terms):
if term in lines:
if len(terms) > idx + 1:
term_next = terms[idx + 1]
if str.isalpha(term_next):
result_phrase = "{} {}".format(term, term_next)
results.add(result_phrase)
except Exception as e:
print(("{}: {}: {}".format(key, len(results), str(e))))
if len(results) > self.limit:
break
output_file = open(output_file, "w")
for phrase in results:
print(phrase, file=output_file)
示例13: test_reject_ephemeral_attempt
def test_reject_ephemeral_attempt(self):
if not self._realserver_info:
raise SkipTest("Need real server")
admin=self.make_admin_connection()
bucket_name = 'ephemeral'
users=[('writer',('s3cr3t',[('data_reader', 'ephemeral'), ('data_writer', 'ephemeral')])),
('reader',('s3cr3t',[('data_reader', 'ephemeral')])),
('viewer',('s3cr3t',[('views_reader', 'ephemeral'), ('views_admin', 'ephemeral')]))]
user=users[2]
(userid, password, roles) = user[0],user[1][0],user[1][1]
# add user
try:
admin.bucket_delete(bucket_name)
except:
pass
try:
admin.bucket_create(name=bucket_name,
bucket_type='ephemeral',
ram_quota=100)
except HTTPError:
raise SkipTest("Unable to provision ephemeral bucket")
try:
admin.user_upsert(AuthDomain.Local, userid, password, roles)
admin.wait_ready(bucket_name, timeout=10)
conn_str = "couchbase://{0}/{1}".format(self.cluster_info.host, bucket_name)
bucket = Bucket(connection_string=conn_str,username=userid,password=password)
self.assertIsNotNone(bucket)
self.assertRaisesRegex(NotSupportedError, "Ephemeral", lambda: bucket.query("beer", "brewery_beers", streaming=True, limit=100))
finally:
admin.bucket_delete(bucket_name)
admin.user_remove(AuthDomain.Local, userid)
示例14: createids
def createids():
cb = Bucket('couchbase://172.23.123.38/bucket-1', password='password')
row_iter = cb.n1ql_query(N1QLQuery('select meta().id from `bucket-1` limit 10000'))
for resultid in row_iter:
'''
use following to create the docids set
'''
print(resultid["id"], None)
示例15: _get_documets
def _get_documets(self, bucket_name, field):
bucket = Bucket('couchbase://{ip}/{name}'.format(ip=self.master.ip, name=bucket_name))
if not bucket:
log.info("Bucket connection is not established.")
log.info("Updating {0} in all documents in bucket {1}...".format(field, bucket_name))
query = "SELECT * FROM {0}".format(bucket_name)
for row in bucket.n1ql_query(query):
yield row[bucket.bucket]['_id'], bucket.get(key=row[bucket.bucket]['_id']).value