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")
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")
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)
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
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)
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 )
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')
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 = "******"+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 = "******"+str(x) un.insert(user,{ "name" : names[x%agents]})
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)
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)
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
def _openContainer(self, session): if self.cxn is 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()
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)
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))
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)
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()
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')
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
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
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
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
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))
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))
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)
def test_connections(): version = connect("Keyspace1").describe_version() thread_local = connect_thread_local("Keyspace1") threads = [] for i in xrange(10): threads.append(threading.Thread(target=version_check, args=(thread_local, version))) threads[-1].start() for thread in threads: thread.join()
def main(): client = pycassa.connect() sp = pycassa.ColumnFamily(client, 'HOPE2008', 'Speakers') print "Start %s" % time.time() for name in names: sp.insert( name, { "bio" : bios[int(random.randint(0,len(bios)-1))] } ) print "End %s" % time.time()
def __init__ (self, servers = ['127.0.0.1:9160'], keyspace = "TileCache", column_family = "TileCache", use_ttl="no", **kwargs): Cache.__init__(self, **kwargs) self.keyspace=keyspace self.column_family=column_family if type(servers) is str: servers = map(str.strip, servers.split(",")) self.client = pycassa.connect(keyspace, servers) self.cf = pycassa.ColumnFamily(self.client, column_family)
def test_connections(): version = connect().get_string_property('version') thread_local = connect_thread_local() threads = [] for i in xrange(10): threads.append(threading.Thread(target=version_check, args=(thread_local, version))) threads[-1].start() for thread in threads: thread.join()
def __init__(self, ident, host, port, timeout): self.ident = ident self.client = pycassa.connect(keyspace='logsandra', servers=['%s:%s' % (host, port)], timeout=int(timeout)) self.cf_entries = pycassa.ColumnFamily(self.client, 'entries') self.cf_by_date = pycassa.ColumnFamily(self.client, 'by_date', dict_class=OrderedDict, autopack_names=False)
def rollup(type, hour): now = int(time.time()) conn = pycassa.connect(CASSANDRA['servers']) rollup_time = calc_time(now, hour) src, dest = ROLLUP[(type, hour)] src_cf = pycassa.ColumnFamily(conn, 'Monit', src, super=True) dest_cf = pycassa.ColumnFamily(conn, 'Monit', dest, super=True) if type == 'metric': rollup_metric(src_cf, dest_cf, rollup_time) else: #status rollup_status(src_cf, dest_cf, rollup_time)
def do_warmup(task): cf_name, row_key = task print "Starting row key %s for CF %s" % (row_key, cf_name) conn = pycassa.connect("reverse", ["localhost"]) cf = pycassa.columnfamily.ColumnFamily(conn, cf_name) start_col = "" while start_col is not None: cols = cf.get(row_key, column_start=start_col, column_count=1000) start_col, _ = cols.popitem(last=True) if len(cols) > 1 else (None, None) print "Finished row key %s for CF %s" % (row_key, cf_name)
def __init__(self, column_family): """ ColumnFamily: - Thông tin người dùng - Tìm kiếm - Thông tin vé - Nhật ký hệ thống - Thông tin nhà cung cấp """ # Connect to Cassandra servers client = connect(CASSANDRA_HOSTS) self.db = ColumnFamily(client, CASSANDRA_KEYSPACE, column_family, super=False)
def column_list(request, keyspace, column_family): host = request.session.get('host', None) pool = pycassa.connect(keyspace, [host,]) col_fam = pycassa.ColumnFamily(pool, column_family) raw_data = list(col_fam.get_range()) data = {} for key, columns in raw_data: new_column = {} for k, v in columns.items(): new_column[k] = v data[key] = new_column return render(request, 'client/column_list/column_list.html', {'column_family':column_family, 'keyspace':keyspace, 'data':data})
def test_connections(): version = connect().get_string_property('version') thread_local = connect_thread_local() threads = [] for i in xrange(10): threads.append( threading.Thread(target=version_check, args=(thread_local, version))) threads[-1].start() for thread in threads: thread.join()
def setUp(self): self.client = connect() self.client.login('Keyspace1', {'username': '******', 'password': '******'}) self.cf = ColumnFamily(self.client, 'Keyspace1', 'Standard2', write_consistency_level=ConsistencyLevel.ONE, buffer_size=2, timestamp=self.timestamp, dict_class=TestDict) try: self.timestamp_n = int(self.cf.get('meta')['timestamp']) except NotFoundException: self.timestamp_n = 0 self.clear()
def setUp(self): credentials = {'username': '******', 'password': '******'} self.client = connect('Keyspace1', credentials=credentials) self.cf = ColumnFamily(self.client, 'Standard2', write_consistency_level=ConsistencyLevel.ONE, buffer_size=2, timestamp=self.timestamp, dict_class=TestDict) try: self.timestamp_n = int(self.cf.get('meta')['timestamp']) except NotFoundException: self.timestamp_n = 0 self.clear()
def locations(request): client = pycassa.connect(['10.254.0.2:9160']) location_history = pycassa.ColumnFamily(client, 'HOPE2010', 'LocationHistory', super=True) prefix = "[" postfix = "]" limit = 10 if request.REQUEST.has_key('jsoncallback'): prefix = request.REQUEST['jsoncallback'] + "(" + prefix postfix = postfix + ")" if request.REQUEST.has_key('limit'): _limit = request.REQUEST['limit'] if _limit.isdigit() and int(_limit) < 20: limit = int(_limit) res = "" while res=="": try: # Display the last 10 locations a specific user checked in if request.REQUEST.has_key('user'): user = request.REQUEST['user'] if request.REQUEST.has_key('super'): limit = 900 last_n = list(location_history.get_range(row_count=limit)) res = "\n".join(json.dumps({"user" : user, "x" : r[1][user]['x'], "y" : r[1][user]['y'], "area" : r[1][user]['area'], "button" : r[1][user].get('button',255), "time" : true_time(r[0])}) for r in last_n) # Display the current location of all users elif request.REQUEST.has_key("leica"): lastseen = (list(location_history.get_range(row_count=2))[1][1]) res = "\n".join(["|".join(['',user, str((float(data['x'])-39.)*.02100), str((float(data['y'])-30.)*-.02100), '0', str('0' if data.get('button','255') == '255' else '1')]) for user, data in lastseen.iteritems() if data['z']=='2' ]) prefix = postfix = '' else: lastseen = (list(location_history.get_range(row_count=2))[1][1]) res = ",".join(json.dumps({"user" : user, "x" : lastseen[user]['x'], "y" : lastseen[user]['y'], "z" : lastseen[user]['z'], "area" : lastseen[user]['area'], "button" : lastseen[user].get('button',255)}) for user in lastseen) except: pass return HttpResponse(prefix+res+postfix,mimetype='text/plain')
def main(): client = pycassa.connect('Keyspace1') standard1 = pycassa.ColumnFamily(client, 'Standard1') uni_str = u"数時間" uni_str = uni_str.encode("utf-8") print "Insert row", uni_str print uni_str, standard1.insert(uni_str, {"bar" : "baz"}) print "Read rows" print "???", standard1.get("???") print uni_str, standard1.get(uni_str)
def main(): client = pycassa.connect('Keyspace1') standard1 = pycassa.ColumnFamily(client, 'Standard1') uni_str = u"数時間" uni_str = uni_str.encode("utf-8") print "Insert row", uni_str print uni_str, standard1.insert(uni_str, {"bar": "baz"}) print "Read rows" print "???", standard1.get("???") print uni_str, standard1.get(uni_str)
def main(): client = pycassa.connect('Keyspace1') standard1 = pycassa.ColumnFamily(client, 'Standard1') uni_str = u"数時間" uni_str = uni_str.encode("utf-8") asc_str = "foo" print "Read rows" #print asc_str, standard1.get(asc_str) import pdb pdb.set_trace() print uni_str, standard1.get(uni_str)
def do_insert(task): cf_name, row_key, col_count = task print "Starting row key %s for CF %s" % (row_key, cf_name) #automatic send every 100 cols conn = pycassa.connect("reverse", ["localhost"]) cf = pycassa.columnfamily.ColumnFamily(conn, cf_name) mutator = pycassa.batch.Mutator(conn, queue_size=100) data = ("foo" * 10)[:25] for col_name in make_cols(col_count): mutator.insert(cf, row_key, {col_name: data}) mutator.send() print "Finished row key %s for CF %s" % (row_key, cf_name) return
def test_connections(self): def version_check(connection, version): assert connection.describe_version() == version version = connect('Keyspace1').describe_version() thread_local = connect_thread_local('Keyspace1') threads = [] for i in xrange(10): threads.append( threading.Thread(target=version_check, args=(thread_local, version))) threads[-1].start() for thread in threads: thread.join()
def __init__(self, cass_host_list=None): """ @brief Constructor, safe to use no arguments @param cass_host_list List of hostname:ports for cassandra host or cluster @retval Connected object instance """ if not cass_host_list: logging.info('Connecting to Cassandra on localhost...') else: hosts = str(cass_host_list) logging.info('Connecting to Cassandra at "%s"...' % hosts) client = pycassa.connect(cass_host_list) self._kvs = pycassa.ColumnFamily(client, 'Datasets', 'Catalog') logging.info('connected OK.')
def create_store(cls, **kwargs): """ @brief Factory method to create an instance of the cassandra store. @param kwargs keyword arguments to configure the store. @param cass_host_list List of hostname:ports for cassandra host or cluster @retval Deferred, for IStore instance. """ inst = cls(**kwargs) inst.kwargs = kwargs inst.cass_host_list = kwargs.get('cass_host_list', None) inst.keyspace = kwargs.get('keyspace', CF_default_keyspace) inst.colfamily = kwargs.get('colfamily', CF_default_colfamily) inst.cf_super = kwargs.get('cf_super', CF_default_cf_super) inst.key = kwargs.get('key', CF_default_key) if not inst.key: inst.key = str(uuid.uuid4()) if inst.cf_super: inst.namespace = kwargs.get('namespace', CF_default_namespace) if inst.namespace == None: # Must change behavior to set a random namespace so that test don't interfere! inst.namespace = ':' else: if inst.namespace: logging.info( 'Ignoring namespace argument in non super column cassandra store' ) inst.namespace = None if not inst.cass_host_list: logging.info('Connecting to Cassandra on localhost...') else: logging.info('Connecting to Cassandra ks:cf=%s:%s at %s ...' % (inst.keyspace, inst.colfamily, inst.cass_host_list)) inst.client = pycassa.connect(inst.cass_host_list) inst.kvs = pycassa.ColumnFamily(inst.client, inst.keyspace, inst.colfamily, super=inst.cf_super) logging.info('connected to Cassandra... OK.') logging.info('cass_host_list: ' + str(inst.cass_host_list)) logging.info('keyspace: ' + str(inst.keyspace)) logging.info('colfamily: ' + str(inst.colfamily)) logging.info('cf_super: ' + str(inst.cf_super)) logging.info('namespace: ' + str(inst.namespace)) return defer.succeed(inst)
def localMultiset(self, chunks): if chunks == None: return if self.col_fam_name != 'local_indexx': self.col_fam_name = 'local_index' self.pool = pycassa.connect('local_index', ['localhost:9160']) self.col_fam = pycassa.ColumnFamily(self.pool, self.col_fam_name) # TODO: Datenbank beibringen ueber listen zu iterieren try: self.col_fam.batch_insert(chunks) return 0 except Exception as msg: print str(msg) return -1
def setUp(self): credentials = {'username': '******', 'password': '******'} self.client = connect('Keyspace1', credentials=credentials) self.cf = ColumnFamily(self.client, 'Standard2', write_consistency_level=ConsistencyLevel.ONE, timestamp=self.timestamp) self.scf = ColumnFamily(self.client, 'Super1', write_consistency_level=ConsistencyLevel.ONE, super=True, timestamp=self.timestamp) try: self.timestamp_n = int(self.cf.get('meta')['timestamp']) except NotFoundException: self.timestamp_n = 0 self.clear()
def profile(target, repeat=10): """Clears the recent latency stats, runs the target and then gets the latency stats again. """ global rows global cfs nodetool_path = os.path.join(CASSANDRA_PATH, "nodetool") cmd = nodetool_path + " -h localhost cfstats" print "Latency is min, 80th percentile, 95th percentile and max." print target.__doc__ print last_cf_name = None for cf_name, row_def in itertools.product(CF_NAMES, rows): key, cols = row_def if last_cf_name != cf_name: print "Testing CF: %s" % cf_name last_cf_name = cf_name conn = pycassa.connect("reverse", ["localhost"]) cf = pycassa.columnfamily.ColumnFamily(conn, cf_name) latency = [] low_col_warn = False for i in range(repeat): run(cmd) rv = target(cf, key, cols) std_out, std_err = run(cmd) if std_err: raise RuntimeError(std_err) if len(rv) != 100: raise RuntimeError("Did not get 100 columns") assert int(rv.keys()[0] > int(rv.keys()[-1])) this_latency = _parse_latency(cf.column_family, std_out) if this_latency is not None: latency.append(this_latency) latency.sort() stats = (min(latency), percentile(latency, 0.8), percentile(latency, 0.95), max(latency)) print profile_pattern.format(key, *stats) print return
def main(argv): usage = "Usage: dbgetkeys [{Keyspace, Column_Family}]" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) if len(argv) == 2: ksname = argv[0] cfname = argv[1] try: server = "%s:%s" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2)
def setUp(self): self.client = connect() self.client.login('Keyspace1', { 'username': '******', 'password': '******' }) self.cf = ColumnFamily(self.client, 'Keyspace1', 'Standard2', write_consistency_level=ConsistencyLevel.ONE, timestamp=self.timestamp) self.map = ColumnFamilyMap(TestUTF8, self.cf) self.empty_map = ColumnFamilyMap(TestEmpty, self.cf, raw_columns=True) try: self.timestamp_n = int(self.cf.get('meta')['timestamp']) except NotFoundException: self.timestamp_n = 0 self.clear()
def setUp(self): credentials = {'username': '******', 'password': '******'} self.client = connect('Keyspace1', credentials=credentials) self.cf = ColumnFamily(self.client, 'Standard2', write_consistency_level=ConsistencyLevel.ONE, timestamp=self.timestamp, autopack_names=False, autopack_values=False) self.indexed_cf = ColumnFamily(self.client, 'Indexed1', autopack_names=False, autopack_values=False) self.map = ColumnFamilyMap(TestUTF8, self.cf) self.indexed_map = ColumnFamilyMap(TestIndex, self.indexed_cf) self.empty_map = ColumnFamilyMap(TestEmpty, self.cf, raw_columns=True) try: self.timestamp_n = int(self.cf.get('meta')['timestamp']) except NotFoundException: self.timestamp_n = 0 self.clear()
from binary_tactics.player import Player from binary_tactics.units import Squad from stores.store import get_persisted #which is actually buggy in this case. import pycassa pool = pycassa.connect('bt') cf = pycassa.ColumnFamily(pool, 'PLAYERS') p = Player({}, 'player 1', get_persisted(Squad()), {}, {}, {}) foo = {'1': p} cf.insert(foo.keys()[0], foo['1']) === from stores.store import * from binary_tactics.player import Player from binary_tactics.helpers import * from binary_tactics.weapons import * from binary_tactics.units import * from binary_tactics.stone import *
import pycassa from django.conf import settings from django.utils.encoding import force_unicode from django.contrib.sessions.backends.base import SessionBase, CreateError CASSANDRA_HOSTS = getattr(settings, 'CASSANDRA_HOSTS', [ 'localhost:9160', ]) CASSANDRA_SESSIONS_KEYSPACE = getattr(settings, 'CASSANDRA_SESSION_KEYSPACE', 'Keyspace1') CASSANDRA_SESSIONS_COLUMN_FAMILY = getattr(settings, 'CASSANDRA_SESSIONS_COLUMN_FAMILY', 'Standard1') pool = pycassa.connect(CASSANDRA_SESSIONS_KEYSPACE, CASSANDRA_HOSTS) session_cf = pycassa.ColumnFamily(pool, CASSANDRA_SESSIONS_COLUMN_FAMILY) class SessionStore(SessionBase): """ A Cassandra based session store. """ def load(self): try: data = session_cf.get(self.session_key) return self.decode(force_unicode(data['session_data'])) except pycassa.NotFoundException: self.create() return {}
def __init__(self): cfg = config.config().format_config() self.pool = pycassa.connect( 'indexer', [str(cfg['server']) + ':' + str(cfg['port'])]) self.col_fam_name = 'indexx' self.col_fam = pycassa.ColumnFamily(self.pool, self.col_fam_name)
def __init__(self): self.pool = pycassa.connect("dns")
import pycassa from pycassa.index import * pool = pycassa.connect('MyKeyspace') users = pycassa.ColumnFamily(pool, 'User') job_expr = create_index_expression('job_title', 'Developer') clause = create_index_clause([job_expr]) for key, user in users.get_indexed_slices(clause): print key
import pycassa pool = pycassa.connect('SiteAdmin', ['10.30.38.208:9160', '10.30.36.245:9160'] ) col_fam = pycassa.ColumnFamily(pool, 'User') ''' col_fam.batch_insert(dict( Nikolay = dict( fname = 'Nikolay', lname = 'Alejandro', sex = 'male', job_title = 'Manager' ), Yury = dict( fname = 'Yury', job_title = 'Developer' ), Next = dict( fname = 'Next', job_title = 'Pet' ), Smile = dict( fname = 'Yep', job_title = 'Pet' ), Cry = dict( fname = 'No', job_title = 'Pet' ), someone = dict( fname = 'Sure', job_title = 'Pet' ) )) ''' col_fam.insert( 'Yury', { 'lname' : 'BatMan' } ) print col_fam.get( 'Yury' ).keys() print col_fam.get( 'Yury' ) print col_fam.get( 'Smile' ) print col_fam.get( 'Cry' ) print col_fam.get( 'someone' ) print col_fam.get( 'serge' )[ 'job_title' ] print col_fam.get( 'mike', columns = ['lname'] )