当前位置: 首页>>代码示例>>Python>>正文


Python ColumnFamily.insert方法代码示例

本文整理汇总了Python中pycassa.ColumnFamily.insert方法的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily.insert方法的具体用法?Python ColumnFamily.insert怎么用?Python ColumnFamily.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycassa.ColumnFamily的用法示例。


在下文中一共展示了ColumnFamily.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_null_pool_failover

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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()
开发者ID:dln,项目名称:pycassa,代码行数:37,代码来源:test_connection_pooling.py

示例2: TestDefaultValidators

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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)
开发者ID:trhowe,项目名称:pycassa,代码行数:30,代码来源:test_autopacking.py

示例3: setUp

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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)])
开发者ID:trhowe,项目名称:pycassa,代码行数:31,代码来源:test_columnfamily.py

示例4: test_queue_pool_recycle

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
    def test_queue_pool_recycle(self):
        listener = _TestListener()
        pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=1,
                         prefill=True, pool_timeout=0.5, timeout=1,
                         keyspace='PycassaTestKeyspace', credentials=_credentials,
                         listeners=[listener], use_threadlocal=False)

        cf = ColumnFamily(pool, 'Standard1')
        columns = {'col1': 'val', 'col2': 'val'}
        for i in range(10):
            cf.insert('key', columns)

        assert_equal(listener.recycle_count, 5)

        pool.dispose()
        listener.reset()

        # Try with threadlocal=True
        pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=1,
                         prefill=False, pool_timeout=0.5, timeout=1,
                         keyspace='PycassaTestKeyspace', credentials=_credentials,
                         listeners=[listener], use_threadlocal=True)

        cf = ColumnFamily(pool, 'Standard1')
        for i in range(10):
            cf.insert('key', columns)

        pool.dispose()
        assert_equal(listener.recycle_count, 5)
开发者ID:anisnasir,项目名称:pycassa,代码行数:31,代码来源:test_connection_pooling.py

示例5: test_get_indexed_slices_batching

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
    def test_get_indexed_slices_batching(self):
        indexed_cf = ColumnFamily(self.client, 'Indexed1')

        columns = {'birthdate': 1L}

        for i in range(200):
            indexed_cf.insert('key%d' % i, columns)

        expr = index.create_index_expression(column_name='birthdate', value=1L)
        clause = index.create_index_clause([expr], count=10)

        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=2))
        assert_equal(len(result), 10)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=10))
        assert_equal(len(result), 10)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=77))
        assert_equal(len(result), 10)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=200))
        assert_equal(len(result), 10)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=1000))
        assert_equal(len(result), 10)

        clause = index.create_index_clause([expr], count=250)

        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=2))
        assert_equal(len(result), 200)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=10))
        assert_equal(len(result), 200)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=77))
        assert_equal(len(result), 200)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=200))
        assert_equal(len(result), 200)
        result = list(indexed_cf.get_indexed_slices(clause, buffer_size=1000))
        assert_equal(len(result), 200)
开发者ID:dln,项目名称:pycassa,代码行数:36,代码来源:test_columnfamily.py

示例6: test_queue_pool_recycle

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
    def test_queue_pool_recycle(self):
        listener = _TestListener()
        pool = QueuePool(pool_size=5, max_overflow=5, recycle=1,
                         prefill=True, pool_timeout=0.5, timeout=1,
                         keyspace='Keyspace1', credentials=_credentials,
                         listeners=[listener], use_threadlocal=False)

        conn = pool.get()
        cf = ColumnFamily(conn, 'Standard1')
        for i in range(10):
            cf.insert('key', {'col': 'val'})

        conn.return_to_pool()
        assert_equal(listener.recycle_count, 1)

        pool.dispose()
        listener.reset()

        # Try with threadlocal=True
        pool = QueuePool(pool_size=5, max_overflow=5, recycle=10,
                         prefill=True, pool_timeout=0.5, timeout=1,
                         keyspace='Keyspace1', credentials=_credentials,
                         listeners=[listener], use_threadlocal=True)

        conn = pool.get()
        cf = ColumnFamily(conn, 'Standard1')
        for i in range(10):
            cf.insert('key', {'col': 'val'})

        conn.return_to_pool()
        assert_equal(listener.recycle_count, 1)
开发者ID:dln,项目名称:pycassa,代码行数:33,代码来源:test_connection_pooling.py

示例7: __init__

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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')
开发者ID:AloneRoad,项目名称:MELS,代码行数:37,代码来源:active_code.py

示例8: test_basic_pools

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
 def test_basic_pools(self):
     pool = ConnectionPool('PycassaTestKeyspace', credentials=_credentials)
     pool.dispose()
     pool = pool.recreate()
     cf = ColumnFamily(pool, 'Standard1')
     cf.insert('key1', {'col':'val'})
     pool.status()
     pool.dispose()
开发者ID:amxn,项目名称:pycassa,代码行数:10,代码来源:test_connection_pooling.py

示例9: test_has_defaults

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
    def test_has_defaults(self):
        key = uuid.uuid4()
        ColumnFamily.insert(self.map, key, {'strcol': '1'})
        instance = self.map.get(key)

        assert_equal(instance.intcol, TestUTF8.intcol.default)
        assert_equal(instance.floatcol, TestUTF8.floatcol.default)
        assert_equal(instance.datetimecol, TestUTF8.datetimecol.default)
开发者ID:anisnasir,项目名称:pycassa,代码行数:10,代码来源:test_columnfamilymap.py

示例10: test_has_defaults

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
    def test_has_defaults(self):
        key = "TestColumnFamilyMap.test_has_defaults"
        ColumnFamily.insert(self.map, key, {"strcol": "1"})
        instance = self.map.get(key)

        assert_equal(instance.intcol, TestUTF8.intcol.default)
        assert_equal(instance.floatcol, TestUTF8.floatcol.default)
        assert_equal(instance.datetimecol, TestUTF8.datetimecol.default)
开发者ID:bwhite,项目名称:pycassa,代码行数:10,代码来源:test_columnfamilymap.py

示例11: test_basic_pools

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
 def test_basic_pools(self):
     for pool_cls in _pools:
         pool = pool_cls(keyspace='Keyspace1', credentials=_credentials)
         pool.dispose()
         pool = pool.recreate()
         cf = ColumnFamily(pool, 'Standard1')
         cf.insert('key1', {'col':'val'})
         pool.status()
         pool.dispose()
开发者ID:trhowe,项目名称:pycassa,代码行数:11,代码来源:test_connection_pooling.py

示例12: _five_fails

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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)
开发者ID:dln,项目名称:pycassa,代码行数:12,代码来源:test_connection_pooling.py

示例13: test_basic_pools

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
 def test_basic_pools(self):
     for pool_cls in _pools:
         print "Pool class: %s" % pool_cls.__name__
         pool = pool_cls(keyspace='Keyspace1', credentials=_credentials)
         pool.dispose()
         pool = pool.recreate()
         conn = pool.get()
         cf = ColumnFamily(conn, 'Standard1')
         cf.insert('key1', {'col':'val'})
         pool.status()
         pool.return_conn(conn)
开发者ID:dln,项目名称:pycassa,代码行数:13,代码来源:test_connection_pooling.py

示例14: setUp

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [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}]
开发者ID:SethCLong,项目名称:pycassa,代码行数:55,代码来源:test_columnfamilymap.py

示例15: TestBigInt

# 需要导入模块: from pycassa import ColumnFamily [as 别名]
# 或者: from pycassa.ColumnFamily import insert [as 别名]
class TestBigInt(unittest.TestCase):

    @classmethod
    def setup_class(cls):
        sys = SystemManager()
        sys.create_column_family(TEST_KS, 'StdInteger', comparator_type=INT_TYPE)

    @classmethod
    def teardown_class(cls):
        sys = SystemManager()
        sys.drop_column_family(TEST_KS, 'StdInteger')

    def setUp(self):
        self.key = 'TestBigInt'
        self.cf = ColumnFamily(pool, 'StdInteger')

    def tearDown(self):
        self.cf.remove(self.key)

    def test_negative_integers(self):
        self.cf.insert(self.key, {-1: '-1'})
        self.cf.insert(self.key, {-12342390: '-12342390'})
        self.cf.insert(self.key, {-255: '-255'})
        self.cf.insert(self.key, {-256: '-256'})
        self.cf.insert(self.key, {-257: '-257'})
        for key, cols in self.cf.get_range():
            self.assertEquals(str(cols.keys()[0]), cols.values()[0])
开发者ID:savinos,项目名称:pycassa,代码行数:29,代码来源:test_autopacking.py


注:本文中的pycassa.ColumnFamily.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。