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


Python Client.delete方法代码示例

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


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

示例1: Memcached

# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import delete [as 别名]
class Memcached(object):
    def __init__(self, servers):
        """Initialize memcached.
        @param servers: an array of servers. Servers can be passed in two forms:
            1. Strings of the form host:port (implies a default weight of 1).
            2. Tuples of the form (host:port, weight) (weight as integer)
        """
        if LIBMC:
            self._client = Client(servers, comp_threshold=10240, noreply=True)
        else:
            self._client = Client(servers)
        self.timeout = 0

    def reset(self):
        self._client.flush_all()

    def size(self):
        bytes = 0
        stats = self._client.get_stats()
        for name, stat in stats:
            bytes += int(stat["bytes"])
        return bytes

    def keys(self):
        raise MemcachedException(
            "It's not possible to fetch keys from memcached"
        )

    def values(self):
        raise MemcachedException(
            "It's not possible to fetch values from memcached"
        )

    def get(self, key, default=None):
        value = self._client.get(key)
        if value is not None:
            return value
        return default

    def __getitem__(self, key):
        return self._client.get(key)

    def __setitem__(self, key, object):
        if PYLIBMC and not LIBMC:
            self._client.set(
                key,
                object,
                time=self.timeout,
                min_compress_len=1024000,
                compress_level=zlib.Z_BEST_SPEED,
            )
        else:
            self._client.set(key, object, time=self.timeout)

    def __delitem__(self, key):
        self._client.delete(key)
开发者ID:bluedynamics,项目名称:bda.cache,代码行数:58,代码来源:memcached.py

示例2: MCStore

# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import delete [as 别名]
class MCStore(object):
    def __init__(self, server):
        self.server = server
        self.mc = Client([server], do_split=0)

    def __del__(self):
        self.close()

    def __repr__(self):
        return '<MCStore(server=%s)>' % repr(self.server)

    def __str__(self):
        return self.server

    def set(self, key, data, rev=0):
        return bool(self.mc.set(key, data, rev))

    def set_raw(self, key, data, rev=0, flag=0):  # interface for sync data
        if rev < 0:
            raise str(rev)
        return self.mc.set_raw(key, data, rev, flag)

    def get(self, key):
        try:
            r = self.mc.get(key)
            if r is None and self.mc.get_last_error() != 0:
                raise IOError(self.mc.get_last_error())
            return r
        except ValueError:
            self.mc.delete(key)

    def get_raw(self, key):
        r, flag = self.mc.get_raw(key)
        if r is None and self.mc.get_last_error() != 0:
            raise IOError(
                self.mc.get_last_error(), self.mc.get_last_strerror())
        return r, flag

    def get_multi(self, keys):
        return self.mc.get_multi(keys)

    def delete(self, key):
        return bool(self.mc.delete(key))

    def close(self):
        if self.mc is not None:
            self.mc = None
开发者ID:leeccong,项目名称:code,代码行数:49,代码来源:dbclient.py

示例3: SingleServerCase

# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import delete [as 别名]
class SingleServerCase(unittest.TestCase):
    def setUp(self):
        self.mc = Client(["127.0.0.1:21211"])
        self.compressed_mc = Client(["127.0.0.1:21211"], comp_threshold=1024)
        self.noreply_mc = Client(["127.0.0.1:21211"], noreply=True)

    def test_attribute(self):
        "Test attributes are accessible from Python code"
        mc = self.mc
        assert hasattr(mc, 'comp_threshold')
        assert hasattr(mc, 'servers')

    def test_misc(self):
        mc = self.mc
        mc.get_multi(['foo', 'tuiche'])
        mc.delete('foo')
        mc.delete('tuiche')
        assert mc.get('foo') is None
        assert mc.get('tuiche') is None

        mc.set('foo', 'biu')
        mc.set('tuiche', 'bb')
        assert mc.get('foo') == 'biu'
        assert mc.get('tuiche') == 'bb'
        assert (mc.get_multi(['foo', 'tuiche']) ==
                {'foo': 'biu', 'tuiche': 'bb'})
        mc.set_multi({'foo': 1024, 'tuiche': '8964'})
        assert (mc.get_multi(['foo', 'tuiche']) ==
                {'foo': 1024, 'tuiche': '8964'})

    def test_delete(self):
        mc = self.mc
        assert mc.set('smmf', 0xCA909) is True
        assert mc.get('smmf') == 0xCA909
        assert mc.delete('smmf') is True
        assert mc.delete_multi(['smmf']) is True
        assert mc.set('smmf', 0xCA909) is True
        assert mc.delete_multi(['smmf']) is True
        assert mc.delete('smmf') is True
        assert mc.delete('smmf') is True

    def test_incr_decr(self):
        mc = self.mc
        mc.set('wazi', 99)
        assert mc.incr('wazi', 1) == 100
        assert mc.decr('wazi', 1) == 99
        mc.delete('wazi')
        assert mc.incr('wazi', 1) is None
        assert mc.decr('wazi', 1) is None

    def test_cas(self):
        mc = self.mc
        mc.delete('bilinda')
        k1 = 'bilinda'
        v1 = 'butchers'
        assert mc.gets(k1) is None
        mc.set(k1, v1)
        v1_, ck = mc.gets('bilinda')
        v2 = 'ding'
        assert v1 == v1_
        assert mc.cas(k1, v2, 0, ck) is True
        assert mc.cas(k1, v1, 0, ck) is not True
        v2_, ck = mc.gets('bilinda')
        assert v2 == v2_

    def test_large(self):
        mc = self.mc
        BUF_500KB = 'i' * (500 * 1000)
        BUF_1MB = 'i' * (1000 * 1000)
        key_500kb = 'test_500kb'
        key_1mb = 'test_1mb'
        mc.delete(key_500kb)
        mc.delete(key_1mb)
        mc.set(key_500kb, BUF_500KB)
        assert mc.get(key_500kb) == BUF_500KB
        mc.set(key_1mb, BUF_1MB)
        assert mc.get(key_1mb) == BUF_1MB
        mc.delete(key_500kb)
        mc.delete(key_1mb)
        dct = {key_500kb: BUF_500KB, key_1mb: BUF_1MB}
        mc.set_multi(dct)
        assert mc.get_multi(dct.keys()) == dct

    def test_extra_large(self):
        threshold = 1000000
        mc = self.mc
        key_xl = 'test_very_large'
        val = 'i' * threshold
        assert mc.set(key_xl, val)
        assert mc.get(key_xl) == val
        val += 'b'
        assert mc.set(key_xl, val)
        assert mc.get(key_xl) == val

        val = 'i' * (threshold + threshold)
        assert mc.set(key_xl, val)
        assert mc.get(key_xl) == val

        val += 'b'
        assert mc.set(key_xl, val)
#.........这里部分代码省略.........
开发者ID:CloudNuts,项目名称:libmc,代码行数:103,代码来源:test_client.py

示例4: CmemcachedRegressionCase

# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import delete [as 别名]
class CmemcachedRegressionCase(unittest.TestCase):

    def setUp(self):
        host = "127.0.0.1"
        port = 21211
        self.server_addr = '%s:%d' % (host, port)
        self.mc = Client([self.server_addr], comp_threshold=1024)
        if cmemcached is not None:
            self.old_mc = cmemcached.Client([self.server_addr],
                                            comp_threshold=1024)

    def test_set_get(self):
        self.mc.set("key", "value")
        self.assertEqual(self.mc.get("key"), "value")

        self.mc.set("key_int", 1)
        self.assertEqual(self.mc.get("key_int"), True)

        self.mc.set("key_long", int(1234567890))
        self.assertEqual(self.mc.get("key_long"), int(1234567890))

        self.mc.set("key_object", BigObject())
        self.assertEqual(self.mc.get("key_object"), BigObject())

        big_object = BigObject('x', 1000001)
        self.mc.set("key_big_object", big_object)
        self.assertEqual(self.mc.get("key_big_object"), big_object)

    def test_set_get_none(self):
        self.assertEqual(self.mc.set('key', None), True)
        self.assertEqual(self.mc.get('key'), None)

    def test_chinese_set_get(self):
        key = '豆瓣'
        value = '在炎热的夏天我们无法停止上豆瓣'
        self.assertEqual(self.mc.set(key, value), True)

        self.assertEqual(self.mc.get(key), value)

    def test_unicode_set_get(self):
        key = "test_unicode_set_get"
        value = u"中文"
        self.assertEqual(self.mc.set(key, value), True)
        self.assertEqual(self.mc.get(key), value)

    def test_special_key(self):
        key = 'keke a kid'
        value = 1024
        self.assertEqual(self.mc.set(key, value), False)
        self.assertEqual(self.mc.get(key), None)
        key = 'u:keke a kid'
        self.assertEqual(self.mc.set(key, value), False)
        self.assertEqual(self.mc.get(key), None)

    def test_unicode_key(self):
        key1 = u"answer"
        key2 = u"答案"
        bytes_key1 = "answer"
        bytes_key2 = "答案"
        value = 42

        self.assertEqual(self.mc.set(key1, value), True)
        self.assertEqual(self.mc.get(key1), value)

        self.assertEqual(self.mc.set(key2, value), True)
        self.assertEqual(self.mc.get(key2), value)

        self.assertEqual(self.mc.incr(key2), value + 1)
        self.assertEqual(self.mc.get(key2), value + 1)

        self.assertEqual(self.mc.delete(key1), True)
        self.assertEqual(self.mc.get(key1), None)

        self.assertEqual(self.mc.add(key1, value), True)
        self.assertEqual(self.mc.get(key1), value)
        self.assertEqual(self.mc.add(key1, value), False)
        self.assertEqual(self.mc.set(key1, value), True)

        self.assertEqual(self.mc.get(bytes_key1), self.mc.get(key1))
        self.assertEqual(self.mc.get(bytes_key2), self.mc.get(key2))

    def test_add(self):
        key = 'test_add'
        self.mc.delete(key)
        self.assertEqual(self.mc.add(key, 'tt'), True)
        self.assertEqual(self.mc.get(key), 'tt')
        self.assertEqual(self.mc.add(key, 'tt'), 0)
        self.mc.delete(key + '2')
        self.assertEqual(self.mc.add(key + '2', range(10)), True)

    def test_replace(self):
        key = 'test_replace'
        self.mc.delete(key)
        self.assertEqual(self.mc.replace(key, ''), 0)
        self.assertEqual(self.mc.set(key, 'b'), True)
        self.assertEqual(self.mc.replace(key, 'a'), True)
        self.assertEqual(self.mc.get(key), 'a')

    def test_append(self):
        key = "test_append"
#.........这里部分代码省略.........
开发者ID:douban,项目名称:libmc,代码行数:103,代码来源:test_cmemcached_regression.py


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