本文整理汇总了Python中couchbase.Couchbase.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Couchbase.connect方法的具体用法?Python Couchbase.connect怎么用?Python Couchbase.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase.Couchbase
的用法示例。
在下文中一共展示了Couchbase.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def __call__(self, test, benckmark):
try:
self.cbb = Couchbase.connect(bucket='benchmarks', **SHOWFAST)
self.cbf = Couchbase.connect(bucket='feed', **SHOWFAST)
except Exception, e:
logger.warn('Failed to connect to database, {}'.format(e))
return
示例2: script_main
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def script_main(input, output, connection=None, ddoc_name=None):
if os.path.isdir(input):
# Read from the filesystem to a design doc, and try to put it into
# Couchbase. Expects 'input' to be a directory readable by the script,
# and 'output' to be a set of arguments with which to connect to the
# Couchbase server.
cb = connection or Couchbase.connect(**output)
ddoc = fs_to_ddoc(input)
# Now on with design documents
url = ddoc.pop('_id')
name = url.split('/', 1)[1] # URL should be "_design/{name}"
print 'Creating design doc:', name, 'on bucket', output['bucket']
use_devmode = '_design/dev' in input
response = cb.design_create(name, ddoc, use_devmode=use_devmode)
print 'Design doc', name, 'creation result:', response.value
else:
# Output to the filesystem from the given input Couchbase instance and
# the design document name
cb = connection or Couchbase.connect(**input)
if not ddoc_name:
raise AssertionError('No design document name supplied')
print 'Fetching design doc:', ddoc_name
response = cb.design_get(ddoc_name, method='GET')
print 'Design doc', ddoc_name, 'fetch result:', response.value
ddoc = response
ddoc_to_fs(ddoc, output)
示例3: __call__
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def __call__(self, test, benckmark):
showfast = test.test_config.stats_settings.showfast
cbmonitor = test.test_config.stats_settings.cbmonitor
try:
self.cbb = Couchbase.connect(bucket='benchmarks', **showfast)
self.cbf = Couchbase.connect(bucket='feed', **showfast)
except Exception, e:
logger.warn('Failed to connect to database, {}'.format(e))
return
示例4: __init__
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def __init__(
self,
priceType="e43",
echost="api.eve-central.com",
e43host="element-43.com",
psqlhost="localhost",
psqlname="element43",
psqluser="element43",
psqlpass="element43",
psqlport="6432",
cbserver="127.0.0.1",
regionID=10000002,
cbucket="prices",
cbpass="prices",
):
self.priceType = priceType
self.echost = echost
self.e43host = e43host
self.psqlhost = psqlhost
self.psqlname = psqlname
self.psqluser = psqluser
self.psqlpass = psqlpass
self.psqlport = psqlport
self.cache = Couchbase.connect(cbucket, cbserver, password=cbpass)
self.regionID = int(regionID)
typeID = 0
示例5: get_mult_runs_data
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def get_mult_runs_data(design_doc, view_names, x_npy_file, y_npy_file):
cb = Couchbase.connect(bucket=bucket_name, host=host_name)
x = [[0, 0, 0, 0, 0, 0, 0, 0]]
for view_name in view_names:
rows = cb.query(design_doc, view_name)
count = 0
for row in rows:
x.append([row.value[1]['thread_alloc_count'],
row.value[1]['proc_count'],
row.value[1]['thread_alloc_size'],
row.value[2]['mem_free'],
row.value[2]['native_allocated_heap'],
row.value[2]['native_free_heap'],
row.value[2]['mem_total'],
row.value[2]['native_heap'],
row.value[3]['global_class_init'],
row.value[3]['classes_loaded'],
row.value[3]['total_methods_invoc'],
row.value[4]['total_tx'],
row.value[4]['total_rx']])
count = count + 1
print view_name + ' count: ' + `count`
x.remove([0, 0, 0, 0, 0, 0, 0, 0])
joblib.dump(x, x_npy_file)
示例6: getbeer
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def getbeer(self):
cb = Couchbase.connect(bucket='beer-sample')
new_beer = {
"name": "Old Yankee Ale",
"abv": 5.00,
"ibu": 0,
"srm": 0,
"upc": 0,
"type": "beer",
"brewery_id": "cottrell_brewing_co",
"updated": "2012-08-30 20:00:20",
"description": ".A medium-bodied Amber Ale",
"style": "American-Style Amber",
"category": "North American Ale"
}
try:
i = 0
match = randint(0, 100)
ilimit = 100
rows = cb.query("beer", "by_name", limit=ilimit, skip=2, include_docs=True)
for r in rows:
if r.doc.value != None:
i += 1
if i == match:
# todo Key mit uebergeben
new_beer = r.doc.value
except CouchbaseError as e:
print
e
finally:
i = i
return new_beer
"""
示例7: get_insight_data
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def get_insight_data(request):
insight = request.GET["insight"]
abscissa = request.GET["abscissa"]
vary_by = request.GET.get("vary_by")
inputs = json.loads(request.GET["inputs"])
inputs.pop(abscissa)
if vary_by:
inputs.pop(vary_by)
defaults = get_default_inputs(insight)
cb = Couchbase.connect(bucket="experiments", **settings.COUCHBASE_SERVER)
data = defaultdict(list)
for row in cb.query("experiments", "experiments_by_name", key=insight, stale=False):
value = row.value
value_inputs = dict(defaults, **value["inputs"])
if dict(value_inputs, **inputs) == value_inputs:
key = value["inputs"].get(vary_by, defaults.get(vary_by))
data[key].append((value_inputs[abscissa], value["value"]))
for k, v in data.items():
v.sort(key=lambda xy: xy[0])
data = OrderedDict(sorted(data.items()))
content = json.dumps(data)
return HttpResponse(content)
示例8: login_user
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def login_user(request):
state = "Please log in below..."
cb=Couchbase.connect(bucket='default', host='localhost')
username = password = ''
if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')
try :
result = cb.get("user::{0}".format(username)).value
print result
try :
store = result
result = json.loads(result)
except:
result = store
session = {}
if (result['password1'] == password) :
session['username'] = username
sessionname = "SessionDetails::{0}".format(username)
cb.set(sessionname,session)
return render_to_response("deployments.html",{'result':result, 'username' : username})
else :
return render_to_response("auth.html",{'error':"IU", 'message':"Your username or password is invalid"})
except:
return render_to_response("auth.html",{'error':"IU", 'message':"Your username or password is invalid"})
示例9: test_is_instance_of_connection
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def test_is_instance_of_connection(self):
self.assertIsInstance(
Couchbase.connect(host=self.host,
port=self.port,
password=self.bucket_password,
bucket=self.bucket_prefix),
Connection)
示例10: create_account
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def create_account(request):
cb=Couchbase.connect(bucket='default', host='localhost')
uname = request.POST.get('username')
password = request.POST.get('password')
accountname = request.POST.get('accountName')
email = request.POST.get('email')
session = {}
sessionname = "SessionDetails::{0}".format(uname)
session['username'] = uname
cb.set(sessionname,session)
value = {'username' : uname,
'password1':password,
'accountName':accountname,
'email' :email,
'deploy':None}
print value['username']
cb.set("user::{0}".format(uname),json.dumps(value))
result = cb.get("user::{0}".format(uname)).value
print result
return render_to_response('deployments.html', {'result' :result, 'username':uname})
示例11: measure_latency
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def measure_latency(self):
logger.info('Measuring replication latency')
timings = []
found = lambda cb: [
v for v in cb.observe(item).value if v.flags != OBS_NOTFOUND
]
password = self.test_config.bucket.password
for master in self.cluster_spec.yield_masters():
for bucket in self.test_config.buckets:
host, port = master.split(':')
cb = Couchbase.connect(host=host, port=port,
bucket=bucket, password=password)
for _ in range(self.NUM_SAMPLES):
item = uhex()
cb.set(item, item)
t0 = time()
while len(found(cb)) != 2:
sleep(0.001)
latency = 1000 * (time() - t0) # s -> ms
logger.info(latency)
timings.append(latency)
summary = {
'min': round(min(timings), 1),
'max': round(max(timings), 1),
'mean': round(np.mean(timings), 1),
'80th': round(np.percentile(timings, 80), 1),
'90th': round(np.percentile(timings, 90), 1),
'95th': round(np.percentile(timings, 95), 1),
'99th': round(np.percentile(timings, 99), 1),
}
logger.info(pretty_dict(summary))
if hasattr(self, 'experiment'):
self.experiment.post_results(summary['95th'])
示例12: connection
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def connection():
if not hasattr(connection, 'singleton'):
connection.singleton = Couchbase.connect(bucket=settings.COUCHBASE_BUCKET,
host=settings.COUCHBASE_HOSTS,
password=settings.COUCHBASE_PASSWORD,
lockmode=LOCKMODE_WAIT)
return connection.singleton
示例13: update_defaults
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def update_defaults(self):
cb = Couchbase.connect(bucket='exp_defaults', **SF_STORAGE)
cb.set(self.name, {
'id': self.name,
'name': self.experiment['name'],
'inputs': self.experiment['defaults'],
})
示例14: get_insight_defaults
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def get_insight_defaults(request):
cb = Couchbase.connect(bucket="exp_defaults", **settings.COUCHBASE_SERVER)
defaults = [
row.value for row in cb.query("exp_defaults", "all", stale=False)
]
content = json.dumps(defaults)
return HttpResponse(content)
示例15: mngviewAdd
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import connect [as 别名]
def mngviewAdd(request):
cb=Couchbase.connect(bucket='default', host='localhost')
resultsess = cb.get("SessionDetails::{0}".format(request.POST.get('hiduname'))).value
username = resultsess['username']
dep = resultsess['deploymentname']
result = cb.get("user::{0}".format(username)).value
print result
deploymentIndex = 0;
temp ={}
for res in result['deploy'] :
if res['request']['depname'] == dep:
temp = res['request']
break
deploymentIndex = deploymentIndex + 1
temp['status'] = 'RDAD'
temp['cpus'] = request.POST.get('number')
temp['deploymentIndex'] = deploymentIndex
depDoc = "DeploymentRequest::{0}::{1}".format(username,timestamp())
cb.set("{0}".format(depDoc),temp)
resultsess['depDoc'] = depDoc
cb.set ("SessionDetails::{0}".format(username), resultsess)
cpu = request.POST.get('number')
return render_to_response ("progress.html", {'cpu':cpu, 'uname':request.POST.get('hiduname')})