def test_set_saves_value(self): """Test that set saves the key with the value.""" RedisGateway.set_value_for_key('fake_key', 'fake_value') self.assertEquals( RedisGateway.fetch_value_for_key('fake_key'), 'fake_value', )
def fetch_value_for_key(cls, key): """Fetches value from the cache with the provided key. :param str key: :returns str: value """ return RedisGateway.fetch_value_for_key(key)
def test_set_expire(self): """Test that you can specify a TTL on a set and it will expire.""" with freeze_time('2014-01-01T00:00:00'): RedisGateway.set_value_for_key('fake_key', 'fake_value', ttl=10) self.assertEquals( RedisGateway.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:08'): self.assertEquals( RedisGateway.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:11'): self.assertIsNone(RedisGateway.fetch_value_for_key('fake_key'), )
def test_set_expire(self): """Test that you can specify a TTL on a set and it will expire.""" with freeze_time('2014-01-01T00:00:00'): RedisGateway.set_value_for_key('fake_key', 'fake_value', ttl=10) self.assertEquals( RedisGateway.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:08'): self.assertEquals( RedisGateway.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:11'): self.assertIsNone( RedisGateway.fetch_value_for_key('fake_key'), )
def set_value_for_key(cls, key, value, ttl=None): """Sets a value at a specific key. :param str key: :param str value: :param int ttl: (optional) ttl in seconds """ return RedisGateway.set_value_for_key( key, value, ttl=ttl, )
def test_get_returns_none_if_empty(self): """Test that no value is returned by get if it hasn't been saved.""" self.assertIsNone(RedisGateway.fetch_value_for_key('fake_key'))