RedisCacheStore implements CacheStore { @Override public <T> void putAll(List<Entry<T>> values, Duration expiration, CacheContext<T> context) { Map<String, byte[]> cacheValues = Maps.newHashMapWithExpectedSize(values.size()); for (Entry<T> value : values) { cacheValues.put(value.key, context.writer.toJSON(value.value)); } try { redis.multiSet(cacheValues, expiration); } 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 putAll() { Duration expiration = Duration.ofHours(1); List<CacheStore.Entry<TestCache>> values = List.of(new CacheStore.Entry<>("key", new TestCache())); cacheStore.putAll(values, expiration, context); verify(redis).multiSet(anyMap(), eq(expiration)); }
@Test void putAllWithFailure() { Duration expiration = Duration.ofHours(1); doThrow(new RedisException("unexpected")).when(redis).multiSet(anyMap(), eq(expiration)); cacheStore.putAll(List.of(new CacheStore.Entry<>("key", new TestCache())), expiration, context); }