RedisCacheStore implements CacheStore { @Override public <T> void put(String key, T value, Duration expiration, CacheContext<T> context) { try { redis.set(key, context.writer.toJSON(value), expiration, false); } catch (UncheckedIOException | RedisException e) { logger.warn(errorCode("CACHE_STORE_FAILED"), "failed to connect to redis, error={}", e.getMessage(), e); } } RedisCacheStore(RedisImpl redis); @Override T get(String key, CacheContext<T> context); @Override Map<String, T> getAll(String[] keys, CacheContext<T> context); @Override void put(String key, T value, Duration expiration, CacheContext<T> context); @Override void putAll(List<Entry<T>> values, Duration expiration, CacheContext<T> context); @Override boolean delete(String... keys);  }
@Test void put() { Duration expiration = Duration.ofHours(1); var value = new TestCache(); cacheStore.put("key", value, expiration, context); verify(redis).set("key", context.writer.toJSON(value), expiration, false); }
@Test void putWithFailure() { var value = new TestCache(); Duration expiration = Duration.ofHours(1); doThrow(new RedisException("unexpected")).when(redis).set("key", context.writer.toJSON(value), expiration, false); cacheStore.put("key", value, expiration, context); }