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


Python cache.incr方法代码示例

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


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

示例1: _safe_cache_incr

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def _safe_cache_incr(self):
        """ cache.incr that silently handles down cache """
        return self._down_cache_handler_partial()(cache.incr) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:5,代码来源:storages.py

示例2: new_email

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def new_email():
    cache.add('error_email_throttle', 0, settings.DMOJ_EMAIL_THROTTLING[1])
    return cache.incr('error_email_throttle') 
开发者ID:DMOJ,项目名称:online-judge,代码行数:5,代码来源:throttle_mail.py

示例3: observer_evaluate

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def observer_evaluate(self, message):
        """Execute observer evaluation on the worker or throttle."""
        observer_id = message['observer']
        throttle_rate = get_queryobserver_settings()['throttle_rate']
        if throttle_rate <= 0:
            await self._evaluate(observer_id)
            return

        cache_key = throttle_cache_key(observer_id)
        try:
            count = cache.incr(cache_key)
            # Ignore if delayed observer already scheduled.
            if count == 2:
                await self.channel_layer.send(
                    CHANNEL_MAIN,
                    {
                        'type': TYPE_POLL,
                        'observer': observer_id,
                        'interval': throttle_rate,
                    },
                )
        except ValueError:
            count = cache.get_or_set(cache_key, default=1, timeout=throttle_rate)
            # Ignore if cache was set and increased in another thread.
            if count == 1:
                await self._evaluate(observer_id) 
开发者ID:genialis,项目名称:django-rest-framework-reactive,代码行数:28,代码来源:consumers.py

示例4: increment_cache_key

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def increment_cache_key(cache_key):
    try:
        cache.incr(cache_key)
    except ValueError:
        cache.set(cache_key, 1, None) 
开发者ID:c3nav,项目名称:c3nav,代码行数:7,代码来源:stats.py

示例5: test_incr

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def test_incr(self):
        # Cache values can be incremented
        cache.set("answer", 41)
        assert cache.incr("answer") == 42
        assert cache.get("answer") == 42
        assert cache.incr("answer", 10) == 52
        assert cache.get("answer") == 52
        assert cache.incr("answer", -10) == 42
        with pytest.raises(ValueError):
            cache.incr("does_not_exist") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:12,代码来源:test_cache.py

示例6: test_cache_versioning_incr_decr

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def test_cache_versioning_incr_decr(self):
        cache.set("answer1", 37, version=1)
        cache.set("answer1", 42, version=2)
        cache.incr("answer1")
        assert cache.get("answer1", version=1) == 38
        assert cache.get("answer1", version=2) == 42
        cache.decr("answer1")
        assert cache.get("answer1", version=1) == 37
        assert cache.get("answer1", version=2) == 42

        cache.set("answer2", 37, version=1)
        cache.set("answer2", 42, version=2)
        cache.incr("answer2", version=2)
        assert cache.get("answer2", version=1) == 37
        assert cache.get("answer2", version=2) == 43
        cache.decr("answer2", version=2)
        assert cache.get("answer2", version=1) == 37
        assert cache.get("answer2", version=2) == 42

        cache.set("answer3", 37, version=1)
        cache.set("answer3", 42, version=2)
        caches["v2"].incr("answer3")
        assert cache.get("answer3", version=1) == 37
        assert cache.get("answer3", version=2) == 43
        caches["v2"].decr("answer3")
        assert cache.get("answer3", version=1) == 37
        assert cache.get("answer3", version=2) == 42

        cache.set("answer4", 37, version=1)
        cache.set("answer4", 42, version=2)
        caches["v2"].incr("answer4", version=1)
        assert cache.get("answer4", version=1) == 38
        assert cache.get("answer4", version=2) == 42
        caches["v2"].decr("answer4", version=1)
        assert cache.get("answer4", version=1) == 37
        assert cache.get("answer4", version=2) == 42 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:38,代码来源:test_cache.py

示例7: test_incr_range

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def test_incr_range(self):
        cache.set("overwhelm", BIGINT_SIGNED_MAX - 1)
        cache.incr("overwhelm")
        with pytest.raises(IntegrityError):
            cache.incr("overwhelm") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:7,代码来源:test_cache.py

示例8: test_cant_incr_decimals

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def test_cant_incr_decimals(self):
        # Cached values that aren't ints can't be incremented
        cache.set("answer", Decimal("1.1"))
        with pytest.raises(ValueError):
            cache.incr("answer") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:7,代码来源:test_cache.py

示例9: test_set_int_subclass

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import incr [as 别名]
def test_set_int_subclass(self):
        # Storing an int subclass should return that int subclass
        cache.set("myint", MyInt(2))
        val = cache.get("myint")
        assert val.times2() == 4

        # Can't increment it since it's a pickle object on the table, not an
        # integer
        with pytest.raises(ValueError):
            cache.incr("myint") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:12,代码来源:test_cache.py


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