本文整理汇总了Python中pycassa.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
开发者ID:Ramblurr,项目名称:CapstonePython,代码行数:9,代码来源:cassandramodel.py
示例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
开发者ID:openamd,项目名称:webapp,代码行数:7,代码来源:cass.py
示例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
开发者ID:openamd,项目名称:webapp,代码行数:7,代码来源:cass.py
示例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')
开发者ID:openamd,项目名称:public_api,代码行数:30,代码来源:views.py
示例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 )
开发者ID:pombredanne,项目名称:cassandra-bombardier,代码行数:7,代码来源:cassandra-bombardier.py
示例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)
开发者ID:esatterly,项目名称:splunk-cassandra,代码行数:33,代码来源:dblookup.py
示例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')
开发者ID:openamd,项目名称:public_api,代码行数:25,代码来源:views.py
示例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))
开发者ID:bloomonkey,项目名称:cheshire3,代码行数:26,代码来源:cassandra.py
示例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)
开发者ID:othrayte,项目名称:xbmc-module-shove,代码行数:16,代码来源:cassandra.py
示例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)
开发者ID:dln,项目名称:pycassa,代码行数:7,代码来源:test_connection.py
示例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)
开发者ID:akkumar,项目名称:logsandra,代码行数:7,代码来源:__init__.py
示例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()
开发者ID:Cheshire-Grampa,项目名称:cheshire3,代码行数:7,代码来源:cassandra.py
示例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]})
开发者ID:openamd,项目名称:public_api,代码行数:28,代码来源:generate_traffic_pycassa.py
示例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
开发者ID:openamd,项目名称:webapp,代码行数:8,代码来源:cass.py
示例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
开发者ID:openamd,项目名称:webapp,代码行数:8,代码来源:cass.py
示例16: get_last_locations
def get_last_locations(user,n):
try:
client = pycassa.connect(['10.254.0.2:9160'])
location_history = pycassa.ColumnFamily(client, 'HOPE2010', 'LocationHistory')
res = location_history.get_range(row_count=n,super_column=get_badge_id(user))
return list(res)
except:
return None
开发者ID:openamd,项目名称:webapp,代码行数:8,代码来源:cass.py
示例17: _get_column_family
def _get_column_family(self):
if self._column_family is None:
conn = pycassa.connect(self.keyspace, servers=self.servers,
**self.cassandra_options)
self._column_family = \
pycassa.ColumnFamily(conn, self.column_family,
read_consistency_level=self.read_consistency,
write_consistency_level=self.write_consistency)
return self._column_family
开发者ID:kornholi,项目名称:celery,代码行数:9,代码来源:cassandra.py
示例18: pool_connection_one
def pool_connection_one(self, KeyspaceName):
try:
logger.info("Connection to the keyspace '" + KeyspaceName + "' at '" + DB_IP + ":" + DB_PORT + "' ...")
self.pool = pycassa.connect(KeyspaceName, [DB_IP + ":" + DB_PORT])
logger.info("Connection to the keyspace established.")
except Exception as exep:
logger.warning(
"Could not connect to the keyspace '" + KeyspaceName + "' at: " + DB_IP + ":" + DB_PORT + ". | " + str(
exep))
开发者ID:occi,项目名称:TSP-CloudStack,代码行数:9,代码来源:connection.py
示例19: create_con_cf
def create_con_cf(columnfamily_name):
try:
lock = threading.Lock()
lock.acquire()
connection = pycassa.connect([HOST])
cf = pycassa.ColumnFamily(connection, keyspace_name, columnfamily_name)
return cf
except NoServerAvailable, ex:
sys.stderr.write("ERROR: %s\n" % str(ex))
开发者ID:RockyRx,项目名称:civiguard,代码行数:9,代码来源:db_connection.py
示例20: load_from_settings
def load_from_settings(settings, prefix="agamemnon."):
if settings["%skeyspace" % prefix] == "memory":
ds_to_wrap = InMemoryDataStore()
else:
ds_to_wrap = CassandraDataStore(
settings["%skeyspace" % prefix],
pycassa.connect(settings["%skeyspace" % prefix], json.loads(settings["%shost_list" % prefix])),
system_manager=pycassa.system_manager.SystemManager(json.loads(settings["%shost_list" % prefix])[0]),
)
return DataStore(ds_to_wrap)
开发者ID:pombredanne,项目名称:agamemnon,代码行数:10,代码来源:factory.py
注:本文中的pycassa.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论