本文整理汇总了Python中pycassa.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
def connect(self, host=None):
if host is None:
self.pool = pycassa.connect(self.config.keyspace, [self.config.host])
print "connecting to %s" %(self.config.host)
else:
self.pool = pycassa.connect(self.config.keyspace, [host])
print "connecting to %s" %(host)
self.STOCKS2 = pycassa.ColumnFamily(self.pool, "Stocks2")
self.SYMBOLS = pycassa.ColumnFamily(self.pool, "StockSymbols")
示例2: get_fields_for_users
def get_fields_for_users(users,fields):
try:
client = pycassa.connect(['10.254.0.2:9160'])
users = pycassa.ColumnFamily(client, 'HOPE2010', 'Users')
return users.multiget(map(get_badge_id,users),fields)
except:
return None
示例3: get_user_fields
def get_user_fields(user,fields):
try:
client = pycassa.connect(['10.254.0.2:9160'])
users = pycassa.ColumnFamily(client, 'HOPE2010', 'Users')
return users.get(get_badge_id(user),fields)
except:
return None
示例4: talks
def talks(request):
client = pycassa.connect(['10.254.0.2:9160'])
# TODO: Create indices for each talk type
talks = pycassa.ColumnFamily(client, 'HOPE2010', 'Talks')
# Display a specific talk
if request.REQUEST.has_key('title'):
title = request.REQUEST['title']
# FIXME: talks.get(title) doesn't work...
# TODO: switch to talks.multiget
# TODO: can we do talks.get_partial_match ?
talk = list(talks.get_range(row_count=1))
results = "\n".join(json.dumps({"speakers" : json.loads(t[1][title]['speakers']),
"title" : title,
"abstract" : t[1][title]['abstract'],
"time" : t[1][title]['time'],
"track" : t[1][title]['track'],
#"interests" : json.loads(t[1][title]['interests']),
}) for t in talk)
# Display all talks
else:
results = json.dumps([{"speakers" : json.loads(t[1]['speakers']),
"title" : t[1]['title'],
"abstract" : t[1]['abstract'],
"time" : t[1]['time'],
"track" : t[1]['track'],
#"interests" : json.loads(t[1]['interests']),
} for t in talks.get_range()])
return HttpResponse(results,mimetype='text/plain')
示例5: insertDataset
def insertDataset( dataset ):
# connect to Cassandra
cpool = pycassa.connect( KEY_SPACE, [HOST] )
# finding Nemo => navigating to the family
col_family = pycassa.ColumnFamily( cpool, COLUMN_FAMILY )
col_family.batch_insert( dataset )
示例6: main
def main(argv):
usage = "Usage: dblookup [options] {cfpath} {key}"
args, kwargs = parse(argv)
host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST)
port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT)
batchsize = kwargs.get('batchsize', settings.DEFAULT_BATCHSIZE)
if not port.isdigit():
error(output, "Invalid port", 2)
port = int(port)
if not batchsize.isdigit() or int(batchsize) < 1:
error(output, "Invalid batchsize", 2)
batchsize = int(batchsize)
# if len(args) < 2:
# error(output, usage, 2)
cfpath, keycol, fields = args
fields = fields.split(',')
cfpath = cfpath.split('.')
if len(cfpath) != 2:
error(output, "Invalid column family path", 2)
ksname, cfname = cfpath
try:
server = "%s:%d" % (host, port)
pool = pycassa.connect(ksname, [server])
cfam = pycassa.ColumnFamily(pool, cfname)
except pycassa.cassandra.c08.ttypes.InvalidRequestException, e:
error(output, e.why, 2)
示例7: users
def users(request):
client = pycassa.connect(['10.254.0.2:9160'])
users = pycassa.ColumnFamily(client, 'HOPE2010', 'Users')
prefix = ""; postfix = "";
if request.REQUEST.has_key('jsoncallback'):
prefix = request.REQUEST['jsoncallback'] + "(" + prefix
postfix = postfix + ")"
# Display a specific user profile
if request.REQUEST.has_key('id'):
user = request.REQUEST['id']
# FIXME: speakers.get(speaker) doesn't work...
# TODO: switch to speakers.multiget
users = users.get_range(user, row_count=1)
results = json.dumps([{"user" : user,
"name" : u[1]['name'],
"x" : u[1]['x'],
"y" : u[1]['y'],
"interests" : u[1]['interests']} for u in users])
# Display all user profiles
else:
results = json.dumps(list(users.get_range()))
return HttpResponse(prefix+results+postfix, mimetype='text/plain')
示例8: _verifyDatabases
def _verifyDatabases(self, session):
"""Verify Keyspace and ColumnFamilies.
Verify existence of Keyspace and ColumnFamilies, creating if necessary.
"""
try:
self._openContainer(session)
except pycassa.cassandra.ttypes.InvalidRequestException as e:
if e.why == "Keyspace does not exist":
# find a way to create keyspace
with pycassa.connect('system', servers=self.servers) as cxn:
ks_def = pycassa.cassandra.ttypes.KsDef(
self.keyspace,
strategy_class=('org.apache.cassandra.locator.'
'RackUnawareStrategy'),
replication_factor=1,
cf_defs=[]
)
cxn.add_keyspace(ks_def)
self._openContainer(session)
else:
raise ConfigFileException("Cannot connect to Cassandra: {0!r}"
"".format(e.args))
except Exception as e:
raise ConfigFileException("Cannot connect to Cassandra: {0!r}"
"".format(e.args))
示例9: __init__
def __init__(self, engine, **kw):
super(CassandraStore, self).__init__(engine, **kw)
spliturl = urlparse.urlsplit(engine)
_, keyspace, column_family = spliturl[2].split('/')
try:
self._pool = pycassa.connect(keyspace, [spliturl[1]])
self._store = pycassa.ColumnFamily(self._pool, column_family)
except pycassa.InvalidRequestException:
from pycassa.system_manager import SystemManager
system_manager = SystemManager(spliturl[1])
system_manager.create_keyspace(
keyspace, kw.get('replication', 1)
)
system_manager.create_column_family(keyspace, column_family)
self._pool = pycassa.connect(keyspace, [spliturl[1]])
self._store = pycassa.ColumnFamily(self._pool, column_family)
示例10: test_api_version_check
def test_api_version_check(self):
import pycassa.connection
pycassa.connection.API_VERSION = ['FOO']
try:
assert_raises(AssertionError, connect('Keyspace1').describe_version)
finally:
reload(pycassa.connection)
示例11: __init__
def __init__(self, ident, host, port, timeout):
self.ident = ident
self.client = pycassa.connect(['%s:%s' % (host, port)], timeout=int(timeout))
self.cf_entries = pycassa.ColumnFamily(self.client, 'logsandra', 'entries')
self.cf_by_date = pycassa.ColumnFamily(self.client, 'logsandra', 'by_date', dict_class=OrderedDict)
self.cf_categories = pycassa.ColumnFamily(self.client, 'logsandra', 'categories', dict_class=OrderedDict)
示例12: _openContainer
def _openContainer(self, session):
if self.cxn == None:
self.cxn = cxn = pycassa.connect(self.keyspace, servers=self.servers)
if (self.username is not None) and (self.passwd is not None):
cxn.login(credentials={'username': self.username, 'password': self.passwd})
else:
cxn.login()
示例13: main
def main():
client = pycassa.connect()
lh = pycassa.ColumnFamily(client, 'HOPE2008', 'LocationHistory',super=True)
un = pycassa.ColumnFamily(client, 'HOPE2008', 'Users')
locations = [lower_bounds]*agents*2
print "Start %s" % time.time()
for i in xrange(rounds):
key = {}
locations = [x+random.gauss(0,1) for x in locations]
for i,l in enumerate(locations):
if l > upper_bounds:
locations[i] = 2*upper_bounds-l
if l < lower_bounds:
locations[i] = 2*lower_bounds-l
for x in range(agents):
user = "user"+str(x)
key[user] = {'x' : str(locations[2*x]),
'y' : str(locations[2*x+1])}
lh.insert(str(int(end_of_days*1e6-time.time()*1e6)),key)
print "End %s" % time.time()
for x in range(agents):
user = "user"+str(x)
un.insert(user,{ "name" : names[x%agents]})
示例14: update_user_field
def update_user_field(user,field,value):
try:
client = pycassa.connect(['10.254.0.2:9160'])
users = pycassa.ColumnFamily(client, 'HOPE2010', 'Users')
time_ = users.insert(get_badge_id(user),{field : value})
return time_
except:
return None
示例15: update_user_fields
def update_user_fields(user,**kwargs):
try:
client = pycassa.connect(['10.254.0.2:9160'])
users = pycassa.ColumnFamily(client, 'HOPE2010', 'Users')
time_ = users.insert(get_badge_id(user),kwargs.items())
return time_
except:
return None