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_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_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_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_expire_invalid_key(self): key = 'test-4-%s' % time.time() self.redis.delete(key) storage = RedisStorage(self.redis) expect(storage.is_expired('invalid-key')).to_be_true() storage.expire('invalid-key') expect(storage.is_expired('invalid-key')).to_be_true()
def test_can_check_not_expired(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) expect(storage.is_expired(key)).to_be_false()
def test_can_acquire_lock(self): key = 'test-%s' % time.time() self.redis.delete(key) storage = RedisStorage(self.redis) lock = storage.acquire_lock(key) expect(lock).not_to_be_null() locked = storage.acquire_lock(key) expect(locked).to_be_null() storage.release_lock(lock)
def test_can_store_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() storage.store(key, 'woot', expiration=10) value = storage.retrieve(key) expect(value).to_equal('woot')
def configure_material_girl(self): from holmes.material import configure_materials host = self.config.get('MATERIAL_GIRL_REDISHOST') port = self.config.get('MATERIAL_GIRL_REDISPORT') self.redis_material = redis.StrictRedis(host=host, port=port, db=0) self.application.girl = Materializer( storage=RedisStorage(redis=self.redis_material), load_on_cachemiss=self.config.get( 'MATERIAL_GIRL_LOAD_ON_CACHEMISS', True)) configure_materials(self.application.girl, self.application.db, self.config)
def test_can_release_lock(self): key = 'test-release-lock' self.redis.delete(key) storage = RedisStorage(self.redis) lock = storage.acquire_lock(key) expect(lock).not_to_be_null() storage.release_lock(lock) lock = storage.acquire_lock(key) expect(lock).not_to_be_null() storage.release_lock(lock)
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()
def configure_material_girl(self): from holmes.material import configure_materials self.girl = Materializer(storage=RedisStorage( redis=self.redis_material)) configure_materials(self.girl, self.db, self.config)
def test_can_get_null_if_value_not_set(self): storage = RedisStorage(self.redis) expect(storage.retrieve('invalid-key')).to_be_null()