Skip to content

Commit aa5f27f

Browse files
authored
Merge branch '5.2.0' into csc-improvements
2 parents 059eb4d + e96e2e3 commit aa5f27f

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/main/java/redis/clients/jedis/csc/CacheConnection.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ public <T> T executeCommand(final CommandObject<T> commandObject) {
8181
// CACHE MISS !!
8282
cache.getStats().miss();
8383
T value = super.executeCommand(commandObject);
84-
if (value != null) {
85-
cacheEntry = new CacheEntry<>(cacheKey, value, this);
86-
cache.set(cacheKey, cacheEntry);
87-
// this line actually provides a deep copy of cached object instance
88-
value = cacheEntry.getValue();
89-
}
84+
cacheEntry = new CacheEntry<>(cacheKey, value, this);
85+
clientSideCache.set(cacheKey, cacheEntry);
86+
// this line actually provides a deep copy of cached object instance
87+
value = cacheEntry.getValue();
9088
return value;
9189
}
9290

src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.hamcrest.Matchers.hasSize;
66
import static org.junit.Assert.assertEquals;
77
import static org.junit.Assert.assertFalse;
8+
import static org.junit.Assert.assertNull;
89
import static org.junit.Assert.assertTrue;
910

1011
import java.util.ArrayList;
@@ -510,4 +511,38 @@ public void run() {
510511
}
511512
}
512513

514+
@Test
515+
public void testNullValue() throws InterruptedException {
516+
int MAX_SIZE = 20;
517+
String nonExisting = "non-existing-key";
518+
control.del(nonExisting);
519+
520+
TestCache cache = new TestCache(MAX_SIZE, new HashMap<>(), DefaultCacheable.INSTANCE);
521+
522+
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), cache)) {
523+
CacheStats stats = cache.getStats();
524+
525+
String val = jedis.get(nonExisting);
526+
assertNull(val);
527+
assertEquals(1, cache.getSize());
528+
assertEquals(0, stats.getHitCount());
529+
assertEquals(1, stats.getMissCount());
530+
531+
val = jedis.get(nonExisting);
532+
assertNull(val);
533+
assertEquals(1, cache.getSize());
534+
assertNull(cache.getCacheEntries().iterator().next().getValue());
535+
assertEquals(1, stats.getHitCount());
536+
assertEquals(1, stats.getMissCount());
537+
538+
control.set(nonExisting, "bar");
539+
val = jedis.get(nonExisting);
540+
assertEquals("bar", val);
541+
assertEquals(1, cache.getSize());
542+
assertEquals("bar", cache.getCacheEntries().iterator().next().getValue());
543+
assertEquals(1, stats.getHitCount());
544+
assertEquals(2, stats.getMissCount());
545+
}
546+
}
547+
513548
}

src/test/java/redis/clients/jedis/csc/UnifiedJedisClientSideCacheTestBase.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ public void simpleWithSimpleMap() {
5959
control.del("foo");
6060
assertThat(map, Matchers.aMapWithSize(1));
6161
assertNull(jedis.get("foo"));
62-
assertThat(map, Matchers.aMapWithSize(0));
63-
assertThat(map, Matchers.aMapWithSize(0));
62+
assertThat(map, Matchers.aMapWithSize(1));
6463
assertNull(jedis.get("foo"));
65-
assertThat(map, Matchers.aMapWithSize(0));
64+
assertThat(map, Matchers.aMapWithSize(1));
6665
}
6766
}
6867

@@ -88,9 +87,9 @@ public void flushAllWithSimpleMap() {
8887
control.flushAll();
8988
assertThat(map, Matchers.aMapWithSize(1));
9089
assertNull(jedis.get("foo"));
91-
assertThat(map, Matchers.aMapWithSize(0));
90+
assertThat(map, Matchers.aMapWithSize(1));
9291
assertNull(jedis.get("foo"));
93-
assertThat(map, Matchers.aMapWithSize(0));
92+
assertThat(map, Matchers.aMapWithSize(1));
9493
}
9594
}
9695

0 commit comments

Comments
 (0)