本文整理汇总了Python中pycassa.ColumnFamily.get方法的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily.get方法的具体用法?Python ColumnFamily.get怎么用?Python ColumnFamily.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycassa.ColumnFamily
的用法示例。
在下文中一共展示了ColumnFamily.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_null_pool_failover
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def test_null_pool_failover(self):
listener = _TestListener()
pool = NullPool(keyspace='Keyspace1', credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160', 'localhost:9160'])
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
for i in range(1,5):
setattr(cf.client._connection.client, 'batch_mutate', _timeout)
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert('key', {'col': 'val'})
assert_equal(listener.failure_count, i)
cf.get('key')
pool.dispose()
listener.reset()
pool = NullPool(keyspace='Keyspace1', credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160', 'localhost:9160'])
threads = []
args = (pool, 'key', {'col':'val'})
for i in range(0, 5):
threads.append(threading.Thread(target=_five_fails, args=args))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.failure_count, 25)
pool.dispose()
示例2: setUp
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class TestSuperColumnFamily:
def setUp(self):
credentials = {'username': 'jsmith', 'password': 'havebadpass'}
self.pool = ConnectionPool(keyspace='Keyspace1', credentials=credentials)
self.cf = ColumnFamily(self.pool, 'Super2')
def tearDown(self):
for key, columns in self.cf.get_range():
self.cf.remove(key)
def test_super(self):
key = 'TestSuperColumnFamily.test_super'
columns = {'1': {'sub1': 'val1', 'sub2': 'val2'}, '2': {'sub3': 'val3', 'sub4': 'val4'}}
assert_raises(NotFoundException, self.cf.get, key)
self.cf.insert(key, columns)
assert_equal(self.cf.get(key), columns)
assert_equal(self.cf.multiget([key]), {key: columns})
assert_equal(list(self.cf.get_range(start=key, finish=key)), [(key, columns)])
def test_super_column_argument(self):
key = 'TestSuperColumnFamily.test_super_columns_argument'
sub12 = {'sub1': 'val1', 'sub2': 'val2'}
sub34 = {'sub3': 'val3', 'sub4': 'val4'}
columns = {'1': sub12, '2': sub34}
self.cf.insert(key, columns)
assert_equal(self.cf.get(key, super_column='1'), sub12)
assert_raises(NotFoundException, self.cf.get, key, super_column='3')
assert_equal(self.cf.multiget([key], super_column='1'), {key: sub12})
assert_equal(list(self.cf.get_range(start=key, finish=key, super_column='1')), [(key, sub12)])
示例3: __init__
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class ActiveCode:
def __init__(self):
# Connect to Cassandra servers
client = connect(cassandra_hosts)
self.u = ColumnFamily(client, cassandra_keyspace,
'Users', super=True)
self.e = Error()
def _gen_active_code(self, length=6, chars=(letters + digits)):
return ''.join([choice(chars) for _ in xrange(length)])
def _is_exist(self, code):
try:
self.u.get('active_codes', super_column=code)
return True
except NotFoundException:
return False
def get_new_code(self):
new = self._gen_active_code()
while self._is_exist(new) is True:
new = self._gen_active_code()
# store in database
self.u.insert('active_codes', {new: {'create_time': str(datetime.now())}})
return new
def active(self, username, active_code):
if self._is_exist(active_code) is False:
return False
self.u.insert('active_codes', {active_code: {'active_time': str(datetime.now()),
'owner': str(username)}})
return True
def stats(self):
return self.u.get('active_codes')
示例4: _five_fails
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def _five_fails(pool, key, column):
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
for i in range(0,5):
setattr(cf.client._connection.client, 'batch_mutate', _timeout)
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert(key, column)
cf.get(key)
示例5: setUp
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class TestSuperColumnFamily:
def setUp(self):
credentials = {'username': 'jsmith', 'password': 'havebadpass'}
self.client = connect_thread_local('Keyspace1', credentials=credentials)
self.cf = ColumnFamily(self.client, 'Super2',
write_consistency_level=ConsistencyLevel.ONE,
buffer_size=2, timestamp=self.timestamp,
super=True)
try:
self.timestamp_n = int(self.cf.get('meta')['meta']['timestamp'])
except NotFoundException:
self.timestamp_n = 0
self.clear()
def tearDown(self):
self.cf.insert('meta', {'meta': {'timestamp': str(self.timestamp_n)}})
# Since the timestamp passed to Cassandra will be in the same second
# with the default timestamp function, causing problems with removing
# and inserting (Cassandra doesn't know which is later), we supply our own
def timestamp(self):
self.timestamp_n += 1
return self.timestamp_n
def clear(self):
for key, columns in self.cf.get_range(include_timestamp=True):
for subcolumns in columns.itervalues():
for value, timestamp in subcolumns.itervalues():
self.timestamp_n = max(self.timestamp_n, timestamp)
self.cf.remove(key)
def test_super(self):
key = 'TestSuperColumnFamily.test_super'
columns = {'1': {'sub1': 'val1', 'sub2': 'val2'}, '2': {'sub3': 'val3', 'sub4': 'val4'}}
assert_raises(NotFoundException, self.cf.get, key)
self.cf.insert(key, columns)
assert self.cf.get(key) == columns
assert self.cf.multiget([key]) == {key: columns}
assert list(self.cf.get_range(start=key, finish=key)) == [(key, columns)]
def test_super_column_argument(self):
key = 'TestSuperColumnFamily.test_super_columns_argument'
sub12 = {'sub1': 'val1', 'sub2': 'val2'}
sub34 = {'sub3': 'val3', 'sub4': 'val4'}
columns = {'1': sub12, '2': sub34}
self.cf.insert(key, columns)
assert self.cf.get(key, super_column='1') == sub12
assert_raises(NotFoundException, self.cf.get, key, super_column='3')
assert self.cf.multiget([key], super_column='1') == {key: sub12}
assert list(self.cf.get_range(start=key, finish=key, super_column='1')) == [(key, sub12)]
示例6: TestDefaultValidators
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class TestDefaultValidators(unittest.TestCase):
def setUp(self):
credentials = {"username": "jsmith", "password": "havebadpass"}
self.pool = ConnectionPool(pool_size=5, keyspace="Keyspace1", credentials=credentials)
self.cf_def_valid = ColumnFamily(self.pool, "DefaultValidator")
def tearDown(self):
for key, cols in self.cf_def_valid.get_range():
self.cf_def_valid.remove(key)
self.pool.dispose()
def test_default_validated_columns(self):
key = "key1"
col_cf = {"aaaaaa": 1L}
col_cm = {"subcol": TIME1}
col_ncf = {"aaaaaa": TIME1}
col_ncm = {"subcol": 1L}
# Both of these inserts work, as cf allows
# longs and cm for 'subcol' allows TIMEUUIDs.
self.cf_def_valid.insert(key, col_cf)
self.cf_def_valid.insert(key, col_cm)
assert self.cf_def_valid.get(key) == {"aaaaaa": 1L, "subcol": TIME1}
assert_raises(TypeError, self.cf_def_valid.insert, key, col_ncf)
assert_raises(TypeError, self.cf_def_valid.insert, key, col_ncm)
示例7: __init__
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class Database:
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 insert(self, key, columns):
key = md5(capwords(key).lower()).hexdigest()
return self.db.insert(key, columns)
def get(self, key, columns=None):
key = md5(capwords(key).lower()).hexdigest()
return self.db.get(key=key, columns=columns)
def remove(self, key, column=None):
key = md5(capwords(key).lower()).hexdigest()
return self.db.remove(key=key, column=column)
示例8: __init__
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class Dictionary:
"""
Nhóm chức năng từ điển:
* Tra từ Anh-Việt
* Tra từ Việt-Anh
"""
def __init__(self):
# Connect to Cassandra servers
client = connect(cassandra_hosts)
self.d = ColumnFamily(client, cassandra_keyspace, 'Dictionary', super=True)
self.u = ColumnFamily(client, cassandra_keyspace, 'Users', super=True)
self.e = Error()
def _lookup(self, keyword, dict_type='en_vi'):
try:
return self.d.get(dict_type, super_column=str(keyword))
except (NotFoundException, InvalidRequestException):
return None
def lookup(self, environ):
try:
session_id = environ['request']['session_id']
except KeyError:
return self.e.authen_error("Thiếu session_id")
try:
self.u.get('session_id', super_column=session_id)
except (NotFoundException, InvalidRequestException):
return self.e.authen_error()
result = self._lookup(environ['request']['keyword'])
result2 = self._lookup(environ['request']['keyword'], 'vi_en')
result3 = self._lookup(environ['request']['keyword'], 'en_en')
if (result is None) and (result2 is None) and (result3 is None):
return self.e.not_found("Từ khóa bạn tìm không có trong từ điển")
xml = []
if result is not None:
xml.append('<result type="en_vi" keyword="%s" mean="%s" spell="%s" status_code="200"/>' \
% (xml_format(environ['request']['keyword']),
xml_format(result['nghia']),
xml_format(result['phien_am_quoc_te'])))
if result2 is not None:
xml.append('<result type="vi_en" keyword="%s" mean="%s" spell="" status_code="200"/>' \
% (xml_format(environ['request']['keyword']),
xml_format(result2['nghia'])))
return '\n\n'.join(xml)
def total_words(self, dict_type='en_vi'):
return self.d.get_count(dict_type)
示例9: TestValidators
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class TestValidators(unittest.TestCase):
def setUp(self):
credentials = {"username": "jsmith", "password": "havebadpass"}
self.pool = ConnectionPool(pool_size=10, keyspace="Keyspace1", credentials=credentials)
self.cf_valid_long = ColumnFamily(self.pool, "ValidatorLong")
self.cf_valid_int = ColumnFamily(self.pool, "ValidatorInt")
self.cf_valid_time = ColumnFamily(self.pool, "ValidatorTime")
self.cf_valid_lex = ColumnFamily(self.pool, "ValidatorLex")
self.cf_valid_ascii = ColumnFamily(self.pool, "ValidatorAscii")
self.cf_valid_utf8 = ColumnFamily(self.pool, "ValidatorUTF8")
self.cf_valid_bytes = ColumnFamily(self.pool, "ValidatorBytes")
self.cfs = [
self.cf_valid_long,
self.cf_valid_int,
self.cf_valid_time,
self.cf_valid_lex,
self.cf_valid_ascii,
self.cf_valid_utf8,
self.cf_valid_bytes,
]
def tearDown(self):
for cf in self.cfs:
for key, cols in cf.get_range():
cf.remove(key)
self.pool.dispose()
def test_validated_columns(self):
key = "key1"
col = {"subcol": 1L}
self.cf_valid_long.insert(key, col)
assert self.cf_valid_long.get(key) == col
col = {"subcol": 1}
self.cf_valid_int.insert(key, col)
assert self.cf_valid_int.get(key) == col
col = {"subcol": TIME1}
self.cf_valid_time.insert(key, col)
assert self.cf_valid_time.get(key) == col
col = {"subcol": uuid.UUID(bytes="aaa aaa aaa aaaa")}
self.cf_valid_lex.insert(key, col)
assert self.cf_valid_lex.get(key) == col
col = {"subcol": "aaa"}
self.cf_valid_ascii.insert(key, col)
assert self.cf_valid_ascii.get(key) == col
col = {"subcol": u"a\u0020"}
self.cf_valid_utf8.insert(key, col)
assert self.cf_valid_utf8.get(key) == col
col = {"subcol": "aaa"}
self.cf_valid_bytes.insert(key, col)
assert self.cf_valid_bytes.get(key) == col
示例10: test_assertion_threadlocal_failover
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def test_assertion_threadlocal_failover(self):
listener = _TestListener()
pool = AssertionPool(keyspace='Keyspace1', credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160', 'localhost:9160'])
conn = pool.get()
cf = ColumnFamily(conn, 'Standard1')
for i in range(1,5):
setattr(cf.client._connection.client, 'batch_mutate', _timeout)
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert('key', {'col': 'val'})
assert_equal(listener.failure_count, i)
cf.get('key')
pool.dispose()
示例11: get
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def get(self, colfam, key, columns=None, column_start="", column_finish="",
column_reversed=False, column_count=100, include_timestamp=False,
super_column=None, read_consistency_level=None):
cf = ColumnFamily(self.db, colfam)
try:
return cf.get(key, columns, column_start, column_finish,
column_reversed, column_count, include_timestamp,
super_column, read_consistency_level)
except NotFoundException:
return None
示例12: setUp
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
class TestSuperColumnFamilyMap:
def setUp(self):
self.client = connect_thread_local()
self.client.login('Keyspace1', {'username': 'jsmith', 'password': 'havebadpass'})
self.cf = ColumnFamily(self.client, 'Keyspace1', 'Super2',
write_consistency_level=ConsistencyLevel.ONE,
timestamp=self.timestamp,
super=True)
self.map = ColumnFamilyMap(TestUTF8, self.cf)
try:
self.timestamp_n = int(self.cf.get('meta')['meta']['timestamp'])
except NotFoundException:
self.timestamp_n = 0
self.clear()
def tearDown(self):
self.cf.insert('meta', {'meta': {'timestamp': str(self.timestamp_n)}})
# Since the timestamp passed to Cassandra will be in the same second
# with the default timestamp function, causing problems with removing
# and inserting (Cassandra doesn't know which is later), we supply our own
def timestamp(self):
self.timestamp_n += 1
return self.timestamp_n
def clear(self):
for key, columns in self.cf.get_range(include_timestamp=True):
for subcolumns in columns.itervalues():
for value, timestamp in subcolumns.itervalues():
self.timestamp_n = max(self.timestamp_n, timestamp)
self.cf.remove(key)
def instance(self, key, super_column):
instance = TestUTF8()
instance.key = key
instance.super_column = super_column
instance.strcol = '1'
instance.intcol = 2
instance.floatcol = 3.5
instance.datetimecol = datetime.now().replace(microsecond=0)
instance.intstrcol = 8
instance.floatstrcol = 4.6
instance.datetimestrcol = datetime.now().replace(microsecond=0)
return instance
def test_super(self):
instance = self.instance('TestSuperColumnFamilyMap.test_super', 'super1')
assert_raises(NotFoundException, self.map.get, instance.key)
self.map.insert(instance)
assert self.map.get(instance.key)[instance.super_column] == instance
assert self.map.multiget([instance.key])[instance.key][instance.super_column] == instance
assert list(self.map.get_range(start=instance.key, finish=instance.key)) == [{instance.super_column: instance}]
示例13: test_queue_threadlocal_failover
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def test_queue_threadlocal_failover(self):
listener = _TestListener()
pool = ConnectionPool(pool_size=1, max_overflow=0, recycle=10000,
prefill=True, timeout=0.05,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=True,
server_list=['localhost:9160', 'localhost:9160'])
cf = ColumnFamily(pool, 'Standard1')
for i in range(1,5):
conn = pool.get()
setattr(conn, 'send_batch_mutate', conn._fail_once)
conn._should_fail = True
conn.return_to_pool()
# The first insert attempt should fail, but failover should occur
# and the insert should succeed
cf.insert('key', {'col': 'val%d' % i, 'col2': 'val'})
assert_equal(listener.failure_count, i)
assert_equal(cf.get('key'), {'col': 'val%d' % i, 'col2': 'val'})
pool.dispose()
listener.reset()
pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
prefill=True, timeout=0.05,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=True,
server_list=['localhost:9160', 'localhost:9160'])
cf = ColumnFamily(pool, 'Standard1')
for i in range(5):
conn = pool.get()
setattr(conn, 'send_batch_mutate', conn._fail_once)
conn._should_fail = True
conn.return_to_pool()
threads = []
args=('key', {'col': 'val', 'col2': 'val'})
for i in range(5):
threads.append(threading.Thread(target=cf.insert, args=args))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.failure_count, 5)
pool.dispose()
示例14: test_default_validated_columns
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def test_default_validated_columns(self):
sys = SystemManager()
sys.create_column_family(TEST_KS, 'DefaultValidator', default_validation_class=LONG_TYPE)
sys.alter_column(TEST_KS, 'DefaultValidator', 'subcol', TIME_UUID_TYPE)
sys.close()
cf = ColumnFamily(pool, 'DefaultValidator')
key = 'key1'
col_cf = {'aaaaaa': 1L}
col_cm = {'subcol': TIME1}
col_ncf = {'aaaaaa': TIME1}
col_ncm = {'subcol': 1L}
# Both of these inserts work, as cf allows
# longs and cm for 'subcol' allows TIMEUUIDs.
cf.insert(key, col_cf)
cf.insert(key, col_cm)
assert_equal(cf.get(key), {'aaaaaa': 1L, 'subcol': TIME1})
示例15: test_validated_columns
# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import get [as 别名]
def test_validated_columns(self):
sys = SystemManager()
sys.create_column_family(TEST_KS, 'Validators',)
sys.alter_column(TEST_KS, 'Validators', 'long', LONG_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'int', INT_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'time', TIME_UUID_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'lex', LEXICAL_UUID_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'ascii', ASCII_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'utf8', UTF8_TYPE)
sys.alter_column(TEST_KS, 'Validators', 'bytes', BYTES_TYPE)
sys.close()
cf = ColumnFamily(pool, 'Validators')
key = 'key1'
col = {'long':1L}
cf.insert(key, col)
assert_equal(cf.get(key)['long'], 1L)
col = {'int':1}
cf.insert(key, col)
assert_equal(cf.get(key)['int'], 1)
col = {'time':TIME1}
cf.insert(key, col)
assert_equal(cf.get(key)['time'], TIME1)
col = {'lex':uuid.UUID(bytes='aaa aaa aaa aaaa')}
cf.insert(key, col)
assert_equal(cf.get(key)['lex'], uuid.UUID(bytes='aaa aaa aaa aaaa'))
col = {'ascii':'aaa'}
cf.insert(key, col)
assert_equal(cf.get(key)['ascii'], 'aaa')
col = {'utf8':u'a\u0020'}
cf.insert(key, col)
assert_equal(cf.get(key)['utf8'], u'a\u0020')
col = {'bytes':'aaa'}
cf.insert(key, col)
assert_equal(cf.get(key)['bytes'], 'aaa')
cf.remove(key)