diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java index 6de0d2b..c748f48 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java +++ b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java @@ -111,7 +111,7 @@ public class RedisMapCacheStore extends RedisCacheStore> imple Objects.requireNonNull(key); Objects.requireNonNull(map); if (map.size() == 0) { - return true; + return exists(key); } final Map targetMap = new HashMap<>(map.size()); diff --git a/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java b/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java index ef6c6f6..1fe4ad2 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java +++ b/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java @@ -54,7 +54,7 @@ public class RedisMapCacheStoreTest { } } - private final static MapCacheStore cacheStore = factory.newMapCacheStore("test", new StringToStringConverter()); + private final static MapCacheStore cacheStore = factory.newMapCacheStore("test:map", new StringToStringConverter()); @Before public void before() { @@ -135,12 +135,14 @@ public class RedisMapCacheStoreTest { Assert.assertTrue("clearMap operation failed!", cacheStore.clearMap(key)); // putAll - // empty map - Assert.assertTrue(cacheStore.putAll(key, new HashMap<>())); + // empty map, key no exist + Assert.assertFalse(cacheStore.putAll(key, new HashMap<>())); // non-empty map Assert.assertTrue(cacheStore.putAll(key, expectedMap)); Assert.assertTrue(expectedMap.keySet().containsAll(cacheStore.mapFieldSet(key))); Assert.assertTrue(expectedMap.values().containsAll(cacheStore.mapValueSet(key))); + // empty map, key exist + Assert.assertTrue(cacheStore.putAll(key, new HashMap<>())); } @Test