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


Python Client.disconnect_all方法代码示例

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


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

示例1: unlock

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def unlock(self, layer, coord, format):
        """ Release a cache lock for this tile.
        """
        mem = Client(self.servers)
        key = tile_key(layer, coord, format, self.revision, self.key_prefix)

        mem.delete(key + "-lock")
        mem.disconnect_all()
开发者ID:kaimw,项目名称:TileStache,代码行数:10,代码来源:Memcache.py

示例2: remove

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def remove(self, layer, coord, format):
        """ Remove a cached tile.
        """
        mem = Client(self.servers)
        key = tile_key(layer, coord, format, self.revision, self.key_prefix)

        mem.delete(key)
        mem.disconnect_all()
开发者ID:kaimw,项目名称:TileStache,代码行数:10,代码来源:Memcache.py

示例3: save

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def save(self, body, layer, coord, format):
        """ Save a cached tile.
        """
        mem = Client(self.servers)
        key = tile_key(layer, coord, format, self.revision, self.key_prefix)

        mem.set(key, body, layer.cache_lifespan or 0)
        mem.disconnect_all()
开发者ID:kaimw,项目名称:TileStache,代码行数:10,代码来源:Memcache.py

示例4: read

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def read(self, layer, coord, format):
        """ Read a cached tile.
        """
        mem = Client(self.servers)
        key = tile_key(layer, coord, format, self.revision, self.key_prefix)

        value = mem.get(key)
        mem.disconnect_all()

        return value
开发者ID:kaimw,项目名称:TileStache,代码行数:12,代码来源:Memcache.py

示例5: save

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
 def save(self, body, layer, coord, format):
     """ Save a cached tile.
     """
     mem = Client(self.servers)
     key = tile_key(layer, coord, format, self.revision, self.key_prefix)
     
     if body is not None:
         body = b64encode(body).decode('ascii')
     
     mem.set(key, body, layer.cache_lifespan or 0)
     mem.disconnect_all()
开发者ID:byrman,项目名称:TileStache,代码行数:13,代码来源:Memcache.py

示例6: read

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
 def read(self, layer, coord, format):
     """ Read a cached tile.
     """
     mem = Client(self.servers)
     key = tile_key(layer, coord, format, self.revision, self.key_prefix)
     
     value = mem.get(key)
     mem.disconnect_all()
     
     if value is None:
         return None
     
     return b64decode(value.encode('ascii'))
开发者ID:byrman,项目名称:TileStache,代码行数:15,代码来源:Memcache.py

示例7: test_memcached_connection

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def test_memcached_connection(self):
        # python-memcached
        print('MEMCACHED_PORT_11211_TCP_ADDR')
        print(os.environ.get('MEMCACHED_PORT_11211_TCP_ADDR'))
        print('MEMCACHED_PORT_11211_TCP_PORT')
        print(os.environ.get('MEMCACHED_PORT_11211_TCP_PORT'))

        mc = Client([
            os.environ.get('MEMCACHED_PORT_11211_TCP_ADDR')
        ], debug=1)

        mc.set('a_string', 'some random string')
        newval = mc.get('a_string')
        self.assertEqual(newval, 'some random string')

        mc.disconnect_all()
开发者ID:hyzhak,项目名称:boilerplate-docker-on-travis,代码行数:18,代码来源:test_connections.py

示例8: lock

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
    def lock(self, layer, coord, format):
        """ Acquire a cache lock for this tile.
        
            Returns nothing, but blocks until the lock has been acquired.
        """
        mem = Client(self.servers)
        key = tile_key(layer, coord, format, self.revision, self.key_prefix)
        due = _time() + layer.stale_lock_timeout

        try:
            while _time() < due:
                if mem.add(key + "-lock", "locked.", layer.stale_lock_timeout):
                    return

                _sleep(0.2)

            mem.set(key + "-lock", "locked.", layer.stale_lock_timeout)
            return

        finally:
            mem.disconnect_all()
开发者ID:kaimw,项目名称:TileStache,代码行数:23,代码来源:Memcache.py

示例9: TestMemcache

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
class TestMemcache(unittest.TestCase):
    def setUp(self):
        # TODO(): unix socket server stuff
        servers = ["127.0.0.1:11211"]
        self.mc = Client(servers, debug=1)

    def tearDown(self):
        self.mc.flush_all()
        self.mc.disconnect_all()

    def check_setget(self, key, val, noreply=False):
        self.mc.set(key, val, noreply=noreply)
        newval = self.mc.get(key)
        self.assertEqual(newval, val)

    def test_setget(self):
        self.check_setget("a_string", "some random string")
        self.check_setget("a_string_2", "some random string", noreply=True)
        self.check_setget("an_integer", 42)
        self.check_setget("an_integer_2", 42, noreply=True)

    def test_delete(self):
        self.check_setget("long", int(1 << 30))
        result = self.mc.delete("long")
        self.assertEqual(result, True)
        self.assertEqual(self.mc.get("long"), None)

    @mock.patch.object(_Host, 'send_cmd')
    @mock.patch.object(_Host, 'readline')
    def test_touch(self, mock_readline, mock_send_cmd):
        with captured_stderr():
            self.mc.touch('key')
        mock_send_cmd.assert_called_with(b'touch key 0')

    def test_get_multi(self):
        self.check_setget("gm_a_string", "some random string")
        self.check_setget("gm_an_integer", 42)
        self.assertEqual(
            self.mc.get_multi(["gm_a_string", "gm_an_integer"]),
            {"gm_an_integer": 42, "gm_a_string": "some random string"})

    def test_get_unknown_value(self):
        self.mc.delete("unknown_value")

        self.assertEqual(self.mc.get("unknown_value"), None)

    def test_setget_foostruct(self):
        f = FooStruct()
        self.check_setget("foostruct", f)
        self.check_setget("foostruct_2", f, noreply=True)

    def test_incr(self):
        self.check_setget("i_an_integer", 42)
        self.assertEqual(self.mc.incr("i_an_integer", 1), 43)

    def test_incr_noreply(self):
        self.check_setget("i_an_integer_2", 42)
        self.assertEqual(self.mc.incr("i_an_integer_2", 1, noreply=True), None)
        self.assertEqual(self.mc.get("i_an_integer_2"), 43)

    def test_decr(self):
        self.check_setget("i_an_integer", 42)
        self.assertEqual(self.mc.decr("i_an_integer", 1), 41)

    def test_decr_noreply(self):
        self.check_setget("i_an_integer_2", 42)
        self.assertEqual(self.mc.decr("i_an_integer_2", 1, noreply=True), None)
        self.assertEqual(self.mc.get("i_an_integer_2"), 41)

    def test_sending_spaces(self):
        try:
            self.mc.set("this has spaces", 1)
        except Client.MemcachedKeyCharacterError as err:
            self.assertTrue("characters not allowed" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyCharacterError, nothing raised")

    def test_sending_control_characters(self):
        try:
            self.mc.set("this\x10has\x11control characters\x02", 1)
        except Client.MemcachedKeyCharacterError as err:
            self.assertTrue("characters not allowed" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyCharacterError, nothing raised")

    def test_sending_key_too_long(self):
        try:
            self.mc.set('a' * SERVER_MAX_KEY_LENGTH + 'a', 1)
        except Client.MemcachedKeyLengthError as err:
            self.assertTrue("length is >" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyLengthError, nothing raised")

        # These should work.
        self.mc.set('a' * SERVER_MAX_KEY_LENGTH, 1)
        self.mc.set('a' * SERVER_MAX_KEY_LENGTH, 1, noreply=True)

#.........这里部分代码省略.........
开发者ID:linsomniac,项目名称:python-memcached,代码行数:103,代码来源:test_memcache.py

示例10: TestMemcache

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import disconnect_all [as 别名]
class TestMemcache(unittest.TestCase):
    def setUp(self):
        # TODO: unix socket server stuff
        servers = ["127.0.0.1:11211"]
        self.mc = Client(servers, debug=1)

    def tearDown(self):
        self.mc.disconnect_all()

    def check_setget(self, key, val, noreply=False):
        self.mc.set(key, val, noreply=noreply)
        newval = self.mc.get(key)
        self.assertEqual(newval, val)

    def test_setget(self):
        self.check_setget("a_string", "some random string")
        self.check_setget("a_string_2", "some random string", noreply=True)
        self.check_setget("an_integer", 42)
        self.check_setget("an_integer_2", 42, noreply=True)

    def test_delete(self):
        self.check_setget("long", int(1 << 30))
        result = self.mc.delete("long")
        self.assertEqual(result, True)
        self.assertEqual(self.mc.get("long"), None)

    def test_get_multi(self):
        self.check_setget("gm_a_string", "some random string")
        self.check_setget("gm_an_integer", 42)
        self.assertEqual(
            self.mc.get_multi(["gm_a_string", "gm_an_integer"]),
            {"gm_an_integer": 42, "gm_a_string": "some random string"})

    def test_get_unknown_value(self):
        self.mc.delete("unknown_value")

        self.assertEqual(self.mc.get("unknown_value"), None)

    def test_setget_foostruct(self):
        f = FooStruct()
        self.check_setget("foostruct", f)
        self.check_setget("foostruct_2", f, noreply=True)

    def test_incr(self):
        self.check_setget("i_an_integer", 42)
        self.assertEqual(self.mc.incr("i_an_integer", 1), 43)

    def test_incr_noreply(self):
        self.check_setget("i_an_integer_2", 42)
        self.assertEqual(self.mc.incr("i_an_integer_2", 1, noreply=True), None)
        self.assertEqual(self.mc.get("i_an_integer_2"), 43)

    def test_decr(self):
        self.check_setget("i_an_integer", 42)
        self.assertEqual(self.mc.decr("i_an_integer", 1), 41)

    def test_decr_noreply(self):
        self.check_setget("i_an_integer_2", 42)
        self.assertEqual(self.mc.decr("i_an_integer_2", 1, noreply=True), None)
        self.assertEqual(self.mc.get("i_an_integer_2"), 41)

    def test_sending_spaces(self):
        try:
            self.mc.set("this has spaces", 1)
        except Client.MemcachedKeyCharacterError as err:
            self.assertTrue("characters not allowed" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyCharacterError, nothing raised")

    def test_sending_control_characters(self):
        try:
            self.mc.set("this\x10has\x11control characters\x02", 1)
        except Client.MemcachedKeyCharacterError as err:
            self.assertTrue("characters not allowed" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyCharacterError, nothing raised")

    def test_sending_key_too_long(self):
        try:
            self.mc.set('a' * SERVER_MAX_KEY_LENGTH + 'a', 1)
        except Client.MemcachedKeyLengthError as err:
            self.assertTrue("length is >" in err.args[0])
        else:
            self.fail(
                "Expected Client.MemcachedKeyLengthError, nothing raised")

        # These should work.
        self.mc.set('a' * SERVER_MAX_KEY_LENGTH, 1)
        self.mc.set('a' * SERVER_MAX_KEY_LENGTH, 1, noreply=True)

    def test_setget_boolean(self):
        """GitHub issue #75. Set/get with boolean values."""
        self.check_setget("bool", True)

    def test_unicode_key(self):
        s = six.u('\u4f1a')
        maxlen = SERVER_MAX_KEY_LENGTH // len(s.encode('utf-8'))
        key = s * maxlen
#.........这里部分代码省略.........
开发者ID:RebelMouseTeam,项目名称:python-memcached,代码行数:103,代码来源:test_memcache.py


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