def test_setnx_timeout(self):
# test that timeout still works for nx=True
res = self.cache.set("test_key_nx", 1, timeout=2, nx=True)
self.assertTrue(res)
time.sleep(3)
res = self.cache.get("test_key_nx", None)
self.assertEqual(res, None)
# test that timeout will not affect key, if it was there
self.cache.set("test_key_nx", 1)
res = self.cache.set("test_key_nx", 2, timeout=2, nx=True)
self.assertFalse(res)
time.sleep(3)
res = self.cache.get("test_key_nx", None)
self.assertEqual(res, 1)
self.cache.delete("test_key_nx")
res = self.cache.get("test_key_nx", None)
self.assertEqual(res, None)
评论列表
文章目录