本文整理汇总了Python中couchbase.bucket.Bucket.get方法的典型用法代码示例。如果您正苦于以下问题:Python Bucket.get方法的具体用法?Python Bucket.get怎么用?Python Bucket.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase.bucket.Bucket
的用法示例。
在下文中一共展示了Bucket.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_dataloss
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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
示例2: post
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def post(self, request, group_id):
c = Bucket('couchbase://localhost/nihongo')
success = 'dunno'
constgroup = group_id.rsplit('_', 1)[0]
print(constgroup)
print('adding new deck')
try:
description = request.POST['description']
print(description)
ckey = 'deck_' + str(uuid4()).replace('-', '_')
newdeck = {'doc_type' : 'deck', 'description' : description, 'deck_name' : description}
newdeck['cards_list'] = []
newdeck['doc_channels'] = [group_id]
c.insert(ckey, newdeck)
group = c.get(group_id).value
print(group.get('decks_list'))
group.get('decks_list').append(ckey)
c.upsert(group_id, group)
success = 'success'
except (BaseException, CouchbaseError) as e:
success = 'error'
print(e)
group = c.get(group_id).value
group_decks = group.get('decks_list')
decks_list = []
for d in group_decks:
try:
deck = c.get(d)
decks_list.append(deck)
except CouchbaseError:
pass
return HttpResponseRedirect(reverse('tutor:group_decks', kwargs={'group_id' : group_id}))
示例3: confirm_ir
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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: get
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def get(self,info):
device_id, temp, type, status = info.split(':')
bucket = Bucket('couchbase://46.101.11.33:8091/devices')
res = bucket.get(device_id, quiet=True)
if res.success:
bucket.n1ql_query('UPSERT INTO devices (KEY,VALUE) VALUES ("%s",{"device_id":"%s", "temp":"%s", "type":"%s", "status":"%s"})' % (device_id, device_id, temp, type, status)).execute()
res = bucket.get(device_id, quiet=True)
return res.value
else:
return {"errCode": "-1", "errMsg": "Could not find device %s" % device_id}
示例5: create_bucket
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def create_bucket(self, name, ramQuotaMB=1024):
"""
1. Create CBS bucket via REST
2. Create client connection and poll until bucket is available
Catch all connection exception and break when KeyNotFound error is thrown
3. Verify all server nodes are in a 'healthy' state before proceeding
Followed the docs below that suggested this approach.
http://docs.couchbase.com/admin/admin/REST/rest-bucket-create.html
"""
log_info("Creating bucket {} with RAM {}".format(name, ramQuotaMB))
data = {
"name": name,
"ramQuotaMB": str(ramQuotaMB),
"authType": "sasl",
"proxyPort": "11211",
"bucketType": "couchbase",
"flushEnabled": "1"
}
resp = self._session.post("{}/pools/default/buckets".format(self.url), data=data)
log_r(resp)
resp.raise_for_status()
# Create client an retry until KeyNotFound error is thrown
start = time.time()
while True:
if time.time() - start > keywords.constants.CLIENT_REQUEST_TIMEOUT:
raise Exception("TIMEOUT while trying to create server buckets.")
try:
bucket = Bucket("couchbase://{}/{}".format(self.host, name))
bucket.get('foo')
except ProtocolError:
log_info("Client Connection failed: Retrying ...")
time.sleep(1)
continue
except TemporaryFailError:
log_info("Failure from server: Retrying ...")
time.sleep(1)
continue
except NotFoundError:
log_info("Key not found error: Bucket is ready!")
break
self.wait_for_ready_state()
return name
示例6: main
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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,代码行数:34,代码来源:couchbase_memcache_mirror.py
示例7: get
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def get(self, request, group_id):
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa")
c = Bucket('couchbase://localhost/nihongo')
group = c.get(group_id).value
group_decks = group.get('decks_list')
decks_list = []
for d in group_decks:
try:
deck = c.get(d)
decks_list.append(deck)
except CouchbaseError:
pass
return render(request, self.template_name, {
'decks_list' : decks_list, 'group' : group.get('group_name'), 'group_id' : group_id
})
示例8: get_phrases
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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)
示例9: __init__
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
class NumericExctractor:
def __init__(self, cb_url, bucket_name, items):
self.distance = 39000
self.output_lines_goal = 1000
self.total_docs = items
self.cb = Bucket("couchbase://{}/{}?operation_timeout=10".format(cb_url, bucket_name), password="password")
self.output_list = list()
def run(self):
n = 0
i = 0
while i<self.output_lines_goal:
n, min = self.read_number(n)
max = min + random.randint(999999, 9999999999)
self.output_list.append("{} max".format(max))
self.output_list.append("{} min".format(min))
self.output_list.append("{}:{} max_min".format(max, min))
i += 1
print(i)
self.write_and_exit()
def read_number(self, n):
step = random.randint(0, self.distance)
n = n + step
if n >= self.total_docs:
self.write_and_exit()
k = hex(n)[2:]
v = self.cb.get(k).value
return n, int(v['time'])
def write_and_exit(self):
f = open("numeric-dgm.txt", "w")
f.write('\n'.join(self.output_list))
f.close()
示例10: get
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def get(self, id):
bucket = Bucket(self._bucketUrl)
try:
result = bucket.get(id)
return result.value
except NotFoundError:
return None
示例11: test_add_concurrent
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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))
示例12: _get_documets
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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
示例13: _get_documets
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
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))
for i in range(self.docs_per_day):
for j in range(self.docs_per_day):
key = "array_dataset-" + str(i) + "-" + str(j)
document = bucket.get(key=key).value
yield key, document
示例14: usernameIsValue
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def usernameIsValue(username):
print username
try:
bucket = Bucket("couchbase://localhost/default")
rv = bucket.get(username)
if rv is not None:
return True
except Exception as e:
print "not found"
send_simple_message(username)
示例15: check_dataloss
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get [as 别名]
def check_dataloss(self, server, bucket, num_items):
from couchbase.bucket import Bucket
from couchbase.exceptions import NotFoundError,CouchbaseError
from lib.memcached.helper.data_helper import VBucketAwareMemcached
self.log.info("########## validating data for bucket : {} ###########".format(bucket))
cb_version= cb_version = RestConnection(server).get_nodes_version()[:3]
if cb_version < "5":
bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name),timeout=5000)
else:
bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name),username=server.rest_username,
password=server.rest_password,timeout=5000)
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 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 CouchbaseError as e:
self.log.error(e)
ok, fail = e.split_results()
if fail:
for key in fail:
try:
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
self.log.info("Total missing keys:{}".format(len(errors)))
self.log.info(errors)
return errors