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


Python Client.delete方法代码示例

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


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

示例1: MemcacheStore

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemcacheStore(DictProxy):

   def __init__(self, host, port):
      from memcache import Client
      self.mc= Client(['%s:%s' % (host, port)])

   def update(self, updates):
      for update in updates:
         (processId, data)= update
         self.mc.set(processId, data)

   def get(self, processId, default= None):
      data= self.mc.get(processId)
      if data == None:
         return default
      return data

   def pop(self, processId):
      data= self.mc.get(processId)
      self.mc.delete(processId)
      return data
      if data == None:
         return default

   def __len__(self):
      return int(self.mc.get_stats()[0][1].get('curr_items'))
开发者ID:richardjmarini,项目名称:Impetus-old,代码行数:28,代码来源:queue.py

示例2: remove

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
 def remove(self, layer, coord, format):
     """ Remove a cached tile.
     """
     mem = Client(self.servers)
     key = tile_key(layer, coord, format, self.revision)
     
     mem.delete(key)
开发者ID:Narrator,项目名称:TileStache,代码行数:9,代码来源:Memcache.py

示例3: remove

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [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

示例4: unlock

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [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

示例5: OODictMongoMemcache

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class OODictMongoMemcache(OODictMongo):
    """Add memcache caching capabilities to a OODictMongo."""

    def __init__(self, memcache_host, mongo_uri, mongo_db, mongo_coll,
                 mongo_id="_id", mongo_client=None, memcache_client=None,
                 _dict=None):
        super(OODictMongoMemcache, self).__init__(
            mongo_uri, mongo_db, mongo_coll, mongo_id,
            mongo_client, _dict
        )
        self._memcache_host = memcache_host
        ## self._memcache_lock = memache_lock
        if memcache_client is None:
            self._memcache = MemcacheClient(memcache_host)
        else:
            self._memcache = memcache_client

    def _memcache_key(self, mongo_id=None):
        return str("%s:%s:%s" % (self._mongo_db, self._mongo_coll,
                             mongo_id or self._dict.get(self._mongo_id, '')))

    def get_from_field(self, key, value, flush=False):
        """Get user by a key:value pair from mongo or memcache."""

        # if searching by id key, then we can find it in memcache
        if not flush and key == self._mongo_id:
            item = self._memcache.get(self._memcache_key(value))
            if item:
                log.info("Cache hit.")
                return self._reinit(item)
        log.info("Cache miss.")
        # didn't find it in memcache, search in mongo and update cache
        super(OODictMongoMemcache, self).get_from_field(key, value)
        item = self._dict
        if item:
            self._memcache.set(self._memcache_key(), item)
            return self._reinit(item)

    def refresh(self, flush=False):
        """Refresh self data from memcache. If flush is True, then
        flush memcache entry and force a refresh from mongo.

        """
        self.get_from_field(self._mongo_id, self._dict[self._mongo_id], flush)

    def save(self):
        """Save user data to storage."""

        self._memcache.set(self._memcache_key(), self._dict)
        super(OODictMongoMemcache, self).save()

    def delete(self):
        """Delete user from storage."""
        self._memcache.delete(self._memcache_key())
        super(OODictMongoMemcache, self).delete()
开发者ID:darrentangdt,项目名称:mist.monitor,代码行数:57,代码来源:dal.py

示例6: MemcachedManager

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemcachedManager():
    class Prefix():
        Session = 'SESSION'
        SysCache = 'ORDER_SYS_CACHE'

        
        
    def __init__(self):
#        if settings.ENVIRONMENT['dev']:
#            pass
#        else:
        self.conn = Client(settings.CACHE['clients'])
        
    def get(self, *arg):
        if len(arg) ==0:
            return None
        arg = [str(i) for i in arg]
        key = PRODUCT_PREFIX+ '|'.join(arg) 
        try:
#            if settings.ENVIRONMENT['dev']:
#                return _localCache.get(key)
#            else:
                return self.conn.get(key)
#            self.conn.
        except:# Client.MemcachedKeyNoneError:
            return None
        
    def set(self, value, timeout, *arg):
        if len(arg) ==0:
            return None  
        arg = [str(i) for i in arg]
        key = PRODUCT_PREFIX+'|'.join(arg)   
#        if settings.ENVIRONMENT['dev']:
#            _localCache[key] = value 
#        else:          
        self.conn.set(key, value, timeout)

    def delete(self, *arg):
        if len(arg) ==0:
            return None
        arg = [str(i) for i in arg]
        key = PRODUCT_PREFIX+'|'.join(arg) 
        try:
#            if settings.ENVIRONMENT['dev']:
#                if _localCache.has_key(key):
#                    _localCache.pop(key)
#            else:                
                self.conn.delete(key)
        except: # Client.MemcachedKeyNoneError:
            return None
开发者ID:yaksea,项目名称:lunchOrder,代码行数:52,代码来源:memcachedManager.py

示例7: MemCacheWrapper

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemCacheWrapper(object):
    """
    Memcache client wrapper.
    No exception raise and add some useful function.
    """

    def __init__(self, servers, logerr=None):
        self.cache = MCClient(servers=servers, debug=False)
        self.logerr = logerr

    def add(self, key, val=1, time=0):
        try:
            return self.cache.add(key, val, time)
        except Exception as e:
            _logger.warning("Exception during `add`: %s", e)

        return None

    def count(self, key, expires=0, delta=1):
        try:
            result = self.cache.incr(key, delta)
            if result is None:
                if not self.cache.add(key, delta, expires):
                    result = self.cache.incr(key, delta)
                else:
                    return delta
            return result
        except Exception as e:
            _logger.warning("Exception during `count`: %s", e)

        return None

    def get(self, key):
        result = None
        try:
            result = self.cache.get(str(key))
        except Exception as e:
            _logger.warning("Exception during `get`: %s", e)

        return result

    def set(self, key, value, expires):
        result = False
        try:
            result = self.cache.set(str(key), value, expires)
        except Exception as e:
            _logger.warning("Exception during `set`: %s", e)

        return result

    def delete(self, key):
        result = False
        try:
            result = self.cache.delete(key)
        except Exception as e:
            _logger.warning("Exception during `del`: %s", e)

        return result
开发者ID:tanhzongbei,项目名称:python-dependence,代码行数:60,代码来源:cache.py

示例8: Memcache

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class Memcache(object):
    """
    address=127.0.0.1:11211
    # TODO 链接断开后没有自动重连机制
    """
    def __init__(self, address):
        from memcache import Client

        self.conn = Client([address])

    def get(self, key):
        return self.conn.get(key)

    def set(self, key, value, timeout):
        self.conn.set(key, value, timeout)

    def delete(self, key):
        self.conn.delete(key)
开发者ID:iamsk,项目名称:tmiddleware,代码行数:20,代码来源:backend.py

示例9: TransactionalMemcacheClient

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class TransactionalMemcacheClient(object):
  def __init__(self, *args):
    from memcache import Client
    self.mc = Client(*args)
    self.del_que = []
    self.random = Random()
    self.random.seed()
    from threading import Thread
    self.del_thread = Thread(target = lambda:self._async_delete())
    self.del_thread.setDaemon(True)
    self.del_thread.start()
  def __getattr__(self, attrname):
    return getattr(self.mc, attrname)
  def _async_delete(self):
    while True:
      try:
        sleep(5)
        while 0 < len(self.del_que):
          target = self.del_que.pop(0)
          if target != None:
            self.mc.delete(target)
      except Exception, e:
        print e
        exit()
开发者ID:kumagi,项目名称:kvtx.py,代码行数:26,代码来源:__init__.py

示例10: MemcacheMemory

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemcacheMemory(Memory):
    """
        Memory gateway to a Memcache server
    """

    def __init__(self, servers=["127.0.0.1:11211"], expire=0, debug=False):
        """
            :param servers: List of servers to use. Please, read
            memcache.Client help.
        """
        self._client = MemcacheClient(servers)
        self._expire = expire
        logging.basicConfig(level=logging.WARNING)
        self.log = logging.getLogger("Memcache-Gateway")
        if debug:
            self.log.setLevel(logging.DEBUG)

    def __getitem__(self, key):
        self.log.debug("Accessing key %s", key)
        value = self._client.get(key)
        if isinstance(value, NotSet):
            value = None
        elif value is None:
            raise KeyError
        return value

    def __setitem__(self, key, value):
        self.log.debug("Setting key")
        if value is None:
            value = NotSet()
        self._client.set(key, value, self._expire)

    def __delitem__(self, key):
        self.log.debug("Deleting key %s", key)
        if self._client.delete(key) == 0:
            raise KeyError

    def open(self, key):
        return KeyFile(self, key)
开发者ID:pcostesi,项目名称:pymemtools,代码行数:41,代码来源:memcache.py

示例11: MemcachedCacheStore

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemcachedCacheStore(AbstractCacheStore):
    servers = ('127.0.0.1:11211')
    def __init__(self, servers=None, debug=False):
        if servers is None:
            servers = self.servers
        from memcache import Client as MemcachedClient
        self._client = MemcachedClient(servers, debug)

    def set(self, key, val, time=0):
        self._client.set(key, val, time)

    def add(self, key, val, time=0):
        res = self._client.add(key, val, time)        
        if not res:
            raise Error('a value for key %r is already in the cache'%key)
        self._data[key] = (val, time)

    def replace(self, key, val, time=0):
        res = self._client.replace(key, val, time)        
        if not res:
            raise Error('a value for key %r is already in the cache'%key)
        self._data[key] = (val, time)

    def delete(self, key):
        res = self._client.delete(key, time=0)        
        if not res:
            raise KeyError(key)
        
    def get(self, key):
        val = self._client.get(key)
        if val is None:
            raise KeyError(key)
        else:
            return val

    def clear(self):
        self._client.flush_all()        
开发者ID:AbhieSpeaks,项目名称:Sick-Beard,代码行数:39,代码来源:CacheStore.py

示例12: PrintFavicon

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]

#.........这里部分代码省略.........
            cherrypy.log("Could not cache icon for domain:%s" % domain, severity=ERROR)

    def iconInCache(self, targetDomain, start):
        icon = self.mc.get("icon-%s" % targetDomain)
        if icon:
            self.mc.incr("counter-hits")
            cherrypy.log("Cache hit:%s" % targetDomain, severity=INFO)

            cherrypy.response.headers["X-Cache"] = "Hit"

            if icon == "DEFAULT":
                self.mc.incr("counter-defaults")
                cherrypy.response.headers["X-Cache"] = "Hit"
                return self.default_icon

            else:
                return Icon(data=icon)

    def writeIcon(self, icon):
        self.writeHeaders(icon)
        return icon.data

    def writeHeaders(self, icon, fmt="%a, %d %b %Y %H:%M:%S %z"):
        # MIME Type
        cherrypy.response.headers["Content-Type"] = icon.type or "image/x-icon"

        # Set caching headers
        cherrypy.response.headers["Cache-Control"] = "public, max-age=2592000"
        cherrypy.response.headers["Expires"] = (datetime.now() + timedelta(days=30)).strftime(fmt)

    def parse(self, url):
        # Get page path
        targetPath = self.urldecode(url)
        if not targetPath.startswith("http"):
            targetPath = "http://%s" % targetPath
        cherrypy.log("Decoded URL:%s" % targetPath, severity=INFO)

        # Split path to get domain
        targetURL = urlparse(targetPath)
        if not targetURL or not targetURL.scheme or not targetURL.netloc:
            raise cherrypy.HTTPError(400, "Malformed URL:%s" % url)

        targetDomain = "%s://%s" % (targetURL.scheme, targetURL.netloc)
        cherrypy.log("URL:%s, domain:%s" % (targetPath, targetDomain), severity=INFO)

        return (targetPath, targetDomain)

    @cherrypy.expose
    def index(self):
        status = {"status": "ok", "counters": dict()}
        for counter in ["requests", "hits", "defaults"]:
            status["counters"][counter] = self.mc.get("counter-%s" % counter)
        return json.dumps(status)

    @cherrypy.expose
    def test(self):
        topSites = open(os.path.join(cherrypy.config["favicon.root"], "topsites.txt"), "r").read().split()
        template = self.env.get_template("test.html")
        return template.render(topSites=topSites)

    @cherrypy.expose
    def clear(self, url):
        cherrypy.log("Incoming cache invalidation request:%s" % url, severity=INFO)

        targetPath, targetDomain = self.parse(str(url))
        self.mc.delete("icon_loc-%s" % targetDomain)

        cherrypy.log("Evicted cache entry for %s" % targetDomain, severity=INFO)

    @cherrypy.expose
    def s(self, url, skipCache="false"):
        start = time()

        if skipCache.lower() == "true":
            skipCache = True
        else:
            skipCache = False

        cherrypy.log("Incoming request:%s (skipCache=%s)" % (url, skipCache), severity=INFO)

        self.mc.incr("counter-requests")

        targetPath, targetDomain = self.parse(str(url))

        icon = (
            (not skipCache and self.iconInCache(targetDomain, start))
            or self.iconInPage(targetDomain, targetPath, start)
            or self.iconAtRoot(targetDomain, start)
        )

        if not icon:
            cherrypy.log("Falling back to default icon for:%s" % targetDomain, severity=INFO)

            self.cacheIcon(targetDomain, "DEFAULT", "DEFAULT_LOC")
            self.mc.incr("counter-defaults")
            icon = self.default_icon

        cherrypy.log("Time taken to process domain:%s %f" % (targetDomain, time() - start), severity=INFO)

        return self.writeIcon(icon)
开发者ID:scouredimage,项目名称:favicon,代码行数:104,代码来源:favicon.py

示例13: TestMemcache

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

    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.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:CanadaHelps,项目名称:python-memcached,代码行数:89,代码来源:test_memcache.py

示例14: TestMemcache

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [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

示例15: MemcacheFeatureStorage

# 需要导入模块: from memcache import Client [as 别名]
# 或者: from memcache.Client import delete [as 别名]
class MemcacheFeatureStorage(FeatureStorage):
    PREFIX = 'georest_buckets'

    support_version = False

    def __init__(self, hosts):
        """ Feature storage implemented in Memcache

        :param list hosts: list of hosts
            1. Strings of the form C{"host:port"}
            2. Tuples of the form C{("host:port", weight)}
        :rtype :class:`MemcacheFeatureStorage`
        """
        self._client = Client(servers=hosts)

    def create_bucket(self, name, overwrite=False, **kwargs):
        bucket_name = self._make_bucket_name(name)

        timestamp = time.time()
        try:
            add_ok = self._client.add(key=bucket_name, val=timestamp)
        except Exception as e:
            raise StorageInternalError(message='add error', e=e)

        if not add_ok:
            if overwrite:
                try:
                    rep_ok = self._client.replace(
                        key=bucket_name, val=timestamp)
                except Exception as e:
                    raise StorageInternalError('replace error', e=e)

                if not rep_ok:
                    raise StorageInternalError(message='failed to replace')
            else:
                raise DuplicatedBucket(name)

        return MemcacheFeatureBucket(name, self._client, str(timestamp))

    def get_bucket(self, name):
        bucket_name = self._make_bucket_name(name)

        try:
            timestamp = self._client.get(bucket_name)
        except Exception as e:
            raise StorageInternalError(message='get error', e=e)

        if not timestamp:
            raise BucketNotFound(name)

        return MemcacheFeatureBucket(name, self._client, str(timestamp))

    def delete_bucket(self, name):
        bucket_name = self._make_bucket_name(name)

        try:
            delete_ok = self._client.delete(bucket_name)
        except Exception as e:
            raise StorageInternalError(message='delete error', e=e)

        if not delete_ok:
            raise BucketNotFound(name)

        return True

    def has_bucket(self, name):
        bucket_name = self._make_bucket_name(name)

        try:
            get_ok = self._client.get(bucket_name)
        except Exception as e:
            raise StorageInternalError(message='get error', e=e)

        return get_ok is not None

    def close(self):
        pass

    def _make_bucket_name(self, name):
        if isinstance(name, unicode):
            name = name.encode('utf-8')
        return '.'.join((self.PREFIX, name))
开发者ID:Kotaimen,项目名称:georest,代码行数:84,代码来源:memcash.py


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