Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover Redis commands for client side caching #3702

Merged
merged 12 commits into from
Feb 15, 2024
11 changes: 7 additions & 4 deletions src/main/java/redis/clients/jedis/ClientSideCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import java.util.function.Function;
import redis.clients.jedis.util.SafeEncoder;

Expand Down Expand Up @@ -67,7 +68,7 @@ private void invalidateKeyAndRespectiveCommandHashes(Object key) {
}
}

final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> command, String... keys) {
final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> command, Object... keys) {

final long hash = getCommandHash(command);

Expand All @@ -79,7 +80,7 @@ final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> comm
value = loader.apply(command);
if (value != null) {
put(hash, value);
for (String key : keys) {
for (Object key : keys) {
ByteBuffer mapKey = makeKeyForKeyToCommandHashes(key);
if (keyToCommandHashes.containsKey(mapKey)) {
keyToCommandHashes.get(mapKey).add(hash);
Expand All @@ -94,8 +95,10 @@ final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> comm
return value;
}

private ByteBuffer makeKeyForKeyToCommandHashes(String key) {
return makeKeyForKeyToCommandHashes(SafeEncoder.encode(key));
private ByteBuffer makeKeyForKeyToCommandHashes(Object key) {
if (key instanceof byte[]) return makeKeyForKeyToCommandHashes((byte[]) key);
else if (key instanceof String) return makeKeyForKeyToCommandHashes(SafeEncoder.encode((String) key));
else throw new AssertionError("" + key.getClass().getSimpleName() + " is not supported. Value: " + String.valueOf(key));
}

private static ByteBuffer makeKeyForKeyToCommandHashes(byte[] b) {
Expand Down
Loading
Loading