Example #1
0
 def test_set(self):
     CacheBase.configure("apps.core.cache.redis.RedisCache",
                         defaults=options.cache_options)
     cache = CacheBase(self.io_loop)
     yield cache.set("testkey", "value")
     value = yield cache.get("testkey",)
     self.assertEqual(value, "value")
     yield cache.delete("testkey")
     value = yield cache.get("testkey",)
     self.assertEqual(value, None)
Example #2
0
    def test_set_dict(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = {"asd": 123, "zxc": "qwe"}
        yield cache.set("testkey", obj)
        value = yield cache.get("testkey",)
        self.assertEqual(isinstance(value, dict), True)
        self.assertItemsEqual(value, {"asd": 123, "zxc": "qwe"})
        yield cache.delete("testkey")
        value = yield cache.get("testkey",)
        self.assertEqual(value, None)
Example #3
0
    def test_set_object(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = A(123123)
        yield cache.set("testkey", obj)
        value = yield cache.get("testkey",)
        self.assertEqual(isinstance(value, A), True)
        self.assertEqual(value.arg, 123123)
        yield cache.delete("testkey")
        value = yield cache.get("testkey",)
        self.assertEqual(value, None)
Example #4
0
 def test_set(self):
     CacheBase.configure(
         "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop)
     cache = CacheBase(self.io_loop)
     yield cache.set("somekey", 1)
     value = yield cache.get("somekey")
     self.assertEqual(value, 1)
Example #5
0
 def test_get(self):
     CacheBase.configure("apps.core.cache.redis.RedisCache",
                         defaults=options.cache_options)
     cache = CacheBase(self.io_loop)
     # 等auth和select完成
     yield sleep(0.1)
     value = yield cache.get("key_not_exist")
     self.assertEqual(value, None)
Example #6
0
    def test_bin(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = {"asd": 123, "zxc": u"啊"}
        yield cache.set("testkey", obj)

        value = yield cache.get("testkey",)
        self.assertItemsEqual(value, {"asd": 123, "zxc": u"啊"})
        self.assertTrue(isinstance(value["zxc"], unicode))

        obj = {"asd": 123, "zxc": b"\x00\x01\x02"}
        yield cache.set("testkey2", obj)

        value = yield cache.get("testkey2",)
        self.assertTrue(isinstance(value["zxc"], bytes))
        self.assertEquals(value["zxc"], b"\x00\x01\x02")
Example #7
0
    def test_size_lru(self):
        CacheBase.configure(
            "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop,
            defaults={"max_size": 2})
        cache = CacheBase()
        yield cache.set("somekey", 1)
        yield cache.set("somekey2", 2)
        # yield cache.set("somekey3", 3)

        value = yield cache.get("somekey")
        self.assertEqual(value, 1)

        yield cache.set("somekey3", 3)  # somekey2被挤出

        value = yield cache.get("somekey")
        self.assertEqual(value, 1)

        value = yield cache.get("somekey2")
        self.assertEqual(value, None)
Example #8
0
 def test_get(self):
     CacheBase.configure(
         "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop)
     cache = CacheBase(self.io_loop)
     value = yield cache.get("key_not_exist")
     self.assertEqual(value, None)