Esempio n. 1
0
 def test_keys(self):
     logging.warn(u'测试 keys 函数及返回长度检查')
     cache.put('a1', 1)
     cache.put('b1', 1555L)
     cache.put('c1', 1)
     cache.put('d1', 2, -1)  # 已过期
     assert cache.get('d1') == None
     cache.put('a2', 1)
     cache.put('b2', 1.0245)
     cache.put('c2', 1)
     assert set(cache.keys('a*')) == set(['a1', 'a2'])
     assert set(cache.keys('*1')) == set(['a1', 'b1', 'c1'])
     assert len(cache.keys('*')) == 6
     assert cache.pop('a1', 'a2') == [1, 1]  # 取多个值,并删除
     assert cache.pop('a1') == None
     assert set(cache.pop('a1', 'b1', 'b2')) == set([1555L,
                                                     1.0245])  # 取多个值,并删除
     assert cache.pop('a1', 'b1', 'b2') == []
Esempio n. 2
0
    def setUp(self):
        """初始化"""
        super(TestRedisCache, self).setUp()

        # 是否缓存的标识
        self.cache_time = 0
        assert cache.ping()
        # 先清空之前的缓存,避免多次测试互相干扰
        cache.clear()
        assert cache.keys('*') == []
Esempio n. 3
0
 def test_base(self):
     """基础函数测试"""
     logging.warn(u'测试 get put 等基本函数')
     key = '123*456'
     value = """ '"'"xxx.!1!1@#$%^&*()_+=-\|][{}?><,.;:'"+-*/.25eww """  # 特殊字符串
     assert cache.get(key) == None
     cache.put(key, value)
     assert cache.get(key) == value
     assert cache.exists(key) == True
     assert cache.pop(key) == value  # 取值,同时删除值
     assert cache.exists(key) == False
     assert cache.get(key) == None
     assert cache.get(key, 0) == 0  # 默认值检查
     # 特殊参数检查
     assert cache.get(None) == None
     assert cache.exists(None) == False
     assert cache.pop(None) == None
     assert cache.pop(None, None) == []
     assert cache.keys(None) == []