コード例 #1
0
ファイル: admin.py プロジェクト: Eavinn/web
 def delete_model(self, request, obj):
     """在管理后台删除一条数据时调用"""
     super().delete_model(request, obj)
     print('delete_model: %s ' % obj)
     # 通过celery异步生成静态的首页
     # generate_static_index_page.delay()
     cache.delete('index_page_data')
コード例 #2
0
ファイル: admin.py プロジェクト: Eavinn/web
 def save_model(self, request, obj, form, change):
     """在管理后台新增或修改了模型数据后调用"""
     super().save_model(request, obj, form, change)
     print('save_model: %s ' % obj)
     # 通过celery异步生成静态的首页
     # generate_static_index_page.delay()
     cache.delete('index_page_data')
コード例 #3
0
 def test_delete_return_value_type_before31(self, cache: RedisCache):
     """delete() returns a int before django version 3.1"""
     cache.set("a", 1)
     res = cache.delete("a")
     assert isinstance(res, int)
     assert res == 1
     res = cache.delete("b")
     assert isinstance(res, int)
     assert res == 0
コード例 #4
0
 def test_delete_return_value_type_new31(self, cache: RedisCache):
     """delete() returns a boolean instead of int since django version 3.1"""
     cache.set("a", 1)
     res = cache.delete("a")
     assert isinstance(res, bool)
     assert res is True
     res = cache.delete("b")
     assert isinstance(res, bool)
     assert res is False
コード例 #5
0
    def test_delete(self, cache: RedisCache):
        cache.set_many({"a": 1, "b": 2, "c": 3})
        res = cache.delete("a")
        assert bool(res) is True

        res = cache.get_many(["a", "b", "c"])
        assert res == {"b": 2, "c": 3}

        res = cache.delete("a")
        assert bool(res) is False
コード例 #6
0
    def test_setnx(self, cache: RedisCache):
        # we should ensure there is no test_key_nx in redis
        cache.delete("test_key_nx")
        res = cache.get("test_key_nx")
        assert res is None

        res = cache.set("test_key_nx", 1, nx=True)
        assert bool(res) is True
        # test that second set will have
        res = cache.set("test_key_nx", 2, nx=True)
        assert res is False
        res = cache.get("test_key_nx")
        assert res == 1

        cache.delete("test_key_nx")
        res = cache.get("test_key_nx")
        assert res is None
コード例 #7
0
    def test_setnx_timeout(self, cache: RedisCache):
        # test that timeout still works for nx=True
        res = cache.set("test_key_nx", 1, timeout=2, nx=True)
        assert res is True
        time.sleep(3)
        res = cache.get("test_key_nx")
        assert res is None

        # test that timeout will not affect key, if it was there
        cache.set("test_key_nx", 1)
        res = cache.set("test_key_nx", 2, timeout=2, nx=True)
        assert res is False
        time.sleep(3)
        res = cache.get("test_key_nx")
        assert res == 1

        cache.delete("test_key_nx")
        res = cache.get("test_key_nx")
        assert res is None
コード例 #8
0
    def test_incr_ignore_check(self, cache: RedisCache):
        if isinstance(cache.client, ShardClient):
            pytest.skip(
                "ShardClient doesn't support argument ignore_key_check to incr"
            )
        if isinstance(cache.client, herd.HerdClient):
            pytest.skip("HerdClient doesn't support incr")

        # key exists check will be skipped and the value will be incremented by
        # '1' which is the default delta
        cache.incr("num", ignore_key_check=True)
        res = cache.get("num")
        assert res == 1
        cache.delete("num")

        # since key doesnt exist it is set to the delta value, 10 in this case
        cache.incr("num", 10, ignore_key_check=True)
        res = cache.get("num")
        assert res == 10
        cache.delete("num")

        # following are just regression checks to make sure it still works as
        # expected with incr max 64 bit signed int
        cache.set("num", 9223372036854775807)

        cache.incr("num", ignore_key_check=True)
        res = cache.get("num")
        assert res == 9223372036854775808

        cache.incr("num", 2, ignore_key_check=True)
        res = cache.get("num")
        assert res == 9223372036854775810

        cache.set("num", 3)

        cache.incr("num", 2, ignore_key_check=True)
        res = cache.get("num")
        assert res == 5