Python pylibmc.NotFound() Examples

The following are 14 code examples of pylibmc.NotFound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pylibmc , or try the search function .
Example #1
Source File: memcached.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def incr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.decr(key, -delta)
        try:
            val = self._cache.incr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #2
Source File: memcached.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def decr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.incr(key, -delta)
        try:
            val = self._cache.decr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #3
Source File: memcached.py    From torngas with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def incr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.decr(key, -delta)
        try:
            val = self._cache.incr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #4
Source File: memcached.py    From torngas with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def decr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.incr(key, -delta)
        try:
            val = self._cache.decr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #5
Source File: memcache_adapter.py    From anom-py with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _cache(self, key, data):
        current_lock = self._lock_value()
        with self.client_pool.reserve() as client:
            while True:
                value, cid = client.gets(key)
                # If there is a lock value in Memcache that is
                # different from our own we have to bail.
                if value and value.startswith(self._lock_prefix) and value != current_lock:
                    return

                # If there isn't a value at all, we have to add one
                # and try again.
                if cid is None:
                    client.add(key, current_lock, self._lock_timeout)
                    continue

                try:
                    return client.cas(key, data, cid, self._item_timeout)

                # There is a small chance that between the `gets` and
                # "now" the key will have been deleted by a concurrent
                # process, so we account for that possibility here.
                except pylibmc.NotFound:  # pragma: no cover
                    return 
Example #6
Source File: memcached.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def incr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.decr(key, -delta)
        try:
            val = self._cache.incr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #7
Source File: memcached.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def decr(self, key, delta=1, version=None):
        key = self.make_key(key, version=version)
        # memcached doesn't support a negative delta
        if delta < 0:
            return self._cache.incr(key, -delta)
        try:
            val = self._cache.decr(key, delta)

        # python-memcache responds to incr on non-existent keys by
        # raising a ValueError, pylibmc by raising a pylibmc.NotFound
        # and Cmemcache returns None. In all cases,
        # we should raise a ValueError though.
        except self.LibraryValueNotFoundException:
            val = None
        if val is None:
            raise ValueError("Key '%s' not found" % key)
        return val 
Example #8
Source File: memcached.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, server, params, library, value_not_found_exception):
        super(BaseMemcachedCache, self).__init__(params)
        if isinstance(server, six.string_types):
            self._servers = server.split(';')
        else:
            self._servers = server

        # The exception type to catch from the underlying library for a key
        # that was not found. This is a ValueError for python-memcache,
        # pylibmc.NotFound for pylibmc, and cmemcache will return None without
        # raising an exception.
        self.LibraryValueNotFoundException = value_not_found_exception

        self._lib = library
        self._options = params.get('OPTIONS', None) 
Example #9
Source File: memcached.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, server, params):
        import pylibmc
        super(PyLibMCCache, self).__init__(server, params,
                                           library=pylibmc,
                                           value_not_found_exception=pylibmc.NotFound) 
Example #10
Source File: memcached.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, server, params, library, value_not_found_exception):
        super(BaseMemcachedCache, self).__init__(params)
        if isinstance(server, string_types):
            self._servers = server.split(';')
        else:
            self._servers = server

        # The exception type to catch from the underlying library for a key
        # that was not found. This is a ValueError for python-memcache,
        # pylibmc.NotFound for pylibmc, and cmemcache will return None without
        # raising an exception.
        self.LibraryValueNotFoundException = value_not_found_exception

        self._lib = library
        self._options = params.get('OPTIONS', None) 
Example #11
Source File: memcached.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, server, params):
        import pylibmc

        super(PyLibMCCache, self).__init__(server, params,
                                           library=pylibmc,
                                           value_not_found_exception=pylibmc.NotFound) 
Example #12
Source File: memcached.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, server, params, library, value_not_found_exception):
        super(BaseMemcachedCache, self).__init__(params)
        if isinstance(server, six.string_types):
            self._servers = server.split(';')
        else:
            self._servers = server

        # The exception type to catch from the underlying library for a key
        # that was not found. This is a ValueError for python-memcache,
        # pylibmc.NotFound for pylibmc, and cmemcache will return None without
        # raising an exception.
        self.LibraryValueNotFoundException = value_not_found_exception

        self._lib = library
        self._options = params.get('OPTIONS', None) 
Example #13
Source File: memcached.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, server, params):
        import pylibmc
        self._local = local()
        super(PyLibMCCache, self).__init__(server, params,
                                           library=pylibmc,
                                           value_not_found_exception=pylibmc.NotFound) 
Example #14
Source File: backends.py    From django-sae with Apache License 2.0 5 votes vote down vote up
def __init__(self, server, params):
        import pylibmc

        self._local = local()
        #pylibmc.NotFound需更改为None,否则在本地会出现错误,模拟的sae.memcache中没有NotFound属性
        super(SaePyLibMCCache, self).__init__(server, params, library=pylibmc, value_not_found_exception=None)