Skip to content

Commit

Permalink
Cover Redis commands for client side caching
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Feb 6, 2024
1 parent d3acff2 commit 52d80cb
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 230 deletions.
14 changes: 8 additions & 6 deletions src/main/java/redis/clients/jedis/ClientSideCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void invalidate0(Object key) {
throw new AssertionError("" + key.getClass().getSimpleName() + " is not supported. Value: " + String.valueOf(key));
}

final ByteBuffer mapKey = makeKey((byte[]) key);
final ByteBuffer mapKey = makeKey0((byte[]) key);

Set<Long> hashes = keyHashes.get(mapKey);
if (hashes != null) {
Expand All @@ -55,7 +55,7 @@ private void invalidate0(Object key) {

protected abstract Object get(long hash);

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 = getHash(command);

Expand All @@ -69,7 +69,7 @@ final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> comm
writeLock.lock();
try {
put(hash, value);
for (String key : keys) {
for (Object key : keys) {
ByteBuffer mapKey = makeKey(key);
if (keyHashes.containsKey(mapKey)) {
keyHashes.get(mapKey).add(hash);
Expand All @@ -89,11 +89,13 @@ final <T> T getValue(Function<CommandObject<T>, T> loader, CommandObject<T> comm

protected abstract long getHash(CommandObject command);

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

private static ByteBuffer makeKey(byte[] b) {
private static ByteBuffer makeKey0(byte[] b) {
return ByteBuffer.wrap(b);
}
}
Loading

0 comments on commit 52d80cb

Please sign in to comment.