Beispiel #1
0
    async def _add(self, key, value, ttl, dumps_fn, namespace):
        start = time.time()
        dumps = dumps_fn or self._serializer.dumps
        ns_key = self._build_key(key, namespace=namespace)

        await self._policy.pre_set(key, value)
        await self._backend.add(ns_key, dumps(value), ttl)
        await self._policy.post_set(key, value)

        logger.info("ADD %s %s (%.4f)s", ns_key, True, time.time() - start)
        return True
Beispiel #2
0
    async def _get(self, key, default, loads_fn, namespace):
        start = time.time()
        loads = loads_fn or self._serializer.loads
        ns_key = self._build_key(key, namespace=namespace)

        await self._policy.pre_get(key)
        value = loads(await self._backend.get(ns_key))
        if value:
            await self._policy.post_get(key)

        logger.info("GET %s %s (%.4f)s", ns_key, value is not None,
                    time.time() - start)
        return value or default
Beispiel #3
0
    async def _multi_get(self, keys, loads_fn, namespace):
        start = time.time()
        loads = loads_fn or self._serializer.loads

        for key in keys:
            await self._policy.pre_get(key)

        ns_keys = [self._build_key(key, namespace=namespace) for key in keys]
        values = await self._backend.multi_get(ns_keys)
        values = [loads(value) for value in values]

        for key in keys:
            await self._policy.post_get(key)

        logger.info("MULTI_GET %s %d (%.4f)s", ns_keys,
                    len([value for value in values if value is not None]),
                    time.time() - start)
        return values
Beispiel #4
0
    async def _multi_set(self, pairs, ttl, dumps_fn, namespace):
        start = time.time()
        dumps = dumps_fn or self._serializer.dumps

        tmp_pairs = []
        for key, value in pairs:
            await self._policy.pre_set(key, value)
            tmp_pairs.append(
                (self._build_key(key, namespace=namespace), dumps(value)))

        await self._backend.multi_set(tmp_pairs, ttl=ttl)

        for key, value in pairs:
            await self._policy.post_set(key, value)

        logger.info("MULTI_SET %s %d (%.4f)s",
                    [key for key, value in tmp_pairs], len(pairs),
                    time.time() - start)
        return True
Beispiel #5
0
 async def _raw(self, command, *args, **kwargs):
     start = time.time()
     ret = await self._backend.raw(command, *args, **kwargs)
     logger.info("%s (%.4f)s", command, time.time() - start)
     return ret
Beispiel #6
0
 async def _exists(self, key, namespace):
     start = time.time()
     ns_key = self._build_key(key, namespace=namespace)
     ret = await self._backend.exists(ns_key)
     logger.info("EXISTS %s %d (%.4f)s", ns_key, ret, time.time() - start)
     return ret
Beispiel #7
0
 async def _delete(self, key, namespace):
     start = time.time()
     ns_key = self._build_key(key, namespace=namespace)
     ret = await self._backend.delete(ns_key)
     logger.info("DELETE %s %d (%.4f)s", ns_key, ret, time.time() - start)
     return ret