def test_can_store_none_as_value(self): key = 'test-%s' % time.time() storage = RedisStorage(self.redis) storage.store(key, None, expiration=10) value = self.redis.get(key) expect(value).to_be_null()
def test_can_get_value(self): key = 'test-3-%s' % time.time() storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=10) value = storage.retrieve(key) expect(value).to_equal('woot')
def test_can_store_value_using_expiration(self): key = 'test-2-%s' % time.time() storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=0.001) time.sleep(0.1) value = self.redis.get(key) expect(value).to_be_null()
def test_can_expire(self): key = 'test-4-%s' % time.time() self.redis.delete(key) storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=10) storage.expire(key) expect(storage.is_expired(key)).to_be_true()
def test_can_store_value_with_grace_value(self): key = 'test-2-%s' % time.time() storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=0.05, grace_period=0.5) time.sleep(0.1) value = self.redis.get(key) value = msgpack.unpackb(value, encoding='utf-8') expect(value).to_equal('woot')
def test_can_store_value(self): key = 'test-%s' % time.time() storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=10) value = self.redis.get(key) value = msgpack.unpackb(value, encoding='utf-8') expect(value).not_to_be_null() expect(value).to_equal('woot')
def test_can_get_even_if_expired(self): key = 'test-4-%s' % time.time() self.redis.delete(key) storage = RedisStorage(self.redis) storage.store(key, 'woot', expiration=10) storage.expire(key) expect(storage.is_expired(key)).to_be_true() value = storage.retrieve(key) expect(value).to_equal('woot')
def test_can_check_expired_again(self): key = 'test-4-%s' % time.time() self.redis.delete(key) storage = RedisStorage(self.redis) expect(storage.is_expired(key)).to_be_true() storage.store(key, 'woot', expiration=10, grace_period=20) expect(storage.is_expired(key, 10)).to_be_false() self.redis.delete(key) expect(storage.is_expired(key, 10)).to_be_true()