From bbc351446d6faa2a15f67e907fb262fb1d53907e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:13:49 +0600 Subject: [PATCH] Re-create csc.util package --- .../clients/jedis/csc/ClientSideCache.java | 4 ++-- .../jedis/csc/{ => util}/CaffeineCSC.java | 18 +++++++++++------- .../clients/jedis/csc/{ => util}/GuavaCSC.java | 14 +++++++++----- ...gWhiteListBlackListClientSideCacheable.java | 3 ++- .../clients/jedis/util/JedisURIHelper.java | 4 ++-- .../jedis/csc/ClientSideCacheLibsTest.java | 2 ++ .../WhiteListBlackListClientSideCacheTest.java | 1 + 7 files changed, 29 insertions(+), 17 deletions(-) rename src/main/java/redis/clients/jedis/csc/{ => util}/CaffeineCSC.java (83%) rename src/main/java/redis/clients/jedis/csc/{ => util}/GuavaCSC.java (88%) rename src/main/java/redis/clients/jedis/csc/{ => util}/StringWhiteListBlackListClientSideCacheable.java (93%) diff --git a/src/main/java/redis/clients/jedis/csc/ClientSideCache.java b/src/main/java/redis/clients/jedis/csc/ClientSideCache.java index e006ea8063..22509e4e2c 100644 --- a/src/main/java/redis/clients/jedis/csc/ClientSideCache.java +++ b/src/main/java/redis/clients/jedis/csc/ClientSideCache.java @@ -12,8 +12,8 @@ /** * The class to manage the client-side caching. User can provide any of implementation of this class to the client - * object; e.g. {@link redis.clients.jedis.csc.CaffeineCSC CaffeineCSC} or - * {@link redis.clients.jedis.csc.GuavaCSC GuavaCSC} or a custom implementation of their own. + * object; e.g. {@link redis.clients.jedis.csc.util.CaffeineCSC CaffeineCSC} or + * {@link redis.clients.jedis.csc.util.GuavaCSC GuavaCSC} or a custom implementation of their own. */ public abstract class ClientSideCache { diff --git a/src/main/java/redis/clients/jedis/csc/CaffeineCSC.java b/src/main/java/redis/clients/jedis/csc/util/CaffeineCSC.java similarity index 83% rename from src/main/java/redis/clients/jedis/csc/CaffeineCSC.java rename to src/main/java/redis/clients/jedis/csc/util/CaffeineCSC.java index 9625644473..4362169550 100644 --- a/src/main/java/redis/clients/jedis/csc/CaffeineCSC.java +++ b/src/main/java/redis/clients/jedis/csc/util/CaffeineCSC.java @@ -1,29 +1,33 @@ -package redis.clients.jedis.csc; +package redis.clients.jedis.csc.util; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import java.util.concurrent.TimeUnit; import net.openhft.hashing.LongHashFunction; + import redis.clients.jedis.CommandObject; import redis.clients.jedis.args.Rawable; +import redis.clients.jedis.csc.ClientSideCache; +import redis.clients.jedis.csc.ClientSideCacheable; +import redis.clients.jedis.csc.DefaultClientSideCacheable; public class CaffeineCSC extends ClientSideCache { private static final LongHashFunction DEFAULT_HASH_FUNCTION = LongHashFunction.xx3(); private final Cache cache; - private final LongHashFunction function; + private final LongHashFunction hashFunction; public CaffeineCSC(Cache caffeineCache, LongHashFunction hashFunction) { super(); this.cache = caffeineCache; - this.function = hashFunction; + this.hashFunction = hashFunction; } public CaffeineCSC(Cache caffeineCache, LongHashFunction function, ClientSideCacheable cacheable) { super(cacheable); this.cache = caffeineCache; - this.function = function; + this.hashFunction = function; } @Override @@ -51,10 +55,10 @@ protected final long getHash(CommandObject command) { long[] nums = new long[command.getArguments().size() + 1]; int idx = 0; for (Rawable raw : command.getArguments()) { - nums[idx++] = function.hashBytes(raw.getRaw()); + nums[idx++] = hashFunction.hashBytes(raw.getRaw()); } - nums[idx] = function.hashInt(command.getBuilder().hashCode()); - return function.hashLongs(nums); + nums[idx] = hashFunction.hashInt(command.getBuilder().hashCode()); + return hashFunction.hashLongs(nums); } public static Builder builder() { diff --git a/src/main/java/redis/clients/jedis/csc/GuavaCSC.java b/src/main/java/redis/clients/jedis/csc/util/GuavaCSC.java similarity index 88% rename from src/main/java/redis/clients/jedis/csc/GuavaCSC.java rename to src/main/java/redis/clients/jedis/csc/util/GuavaCSC.java index a6f55d73dd..e1c9e4f434 100644 --- a/src/main/java/redis/clients/jedis/csc/GuavaCSC.java +++ b/src/main/java/redis/clients/jedis/csc/util/GuavaCSC.java @@ -1,18 +1,22 @@ -package redis.clients.jedis.csc; +package redis.clients.jedis.csc.util; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.hash.HashFunction; import com.google.common.hash.Hasher; import java.util.concurrent.TimeUnit; + import redis.clients.jedis.CommandObject; +import redis.clients.jedis.csc.ClientSideCache; +import redis.clients.jedis.csc.ClientSideCacheable; +import redis.clients.jedis.csc.DefaultClientSideCacheable; public class GuavaCSC extends ClientSideCache { private static final HashFunction DEFAULT_HASH_FUNCTION = com.google.common.hash.Hashing.fingerprint2011(); private final Cache cache; - private final HashFunction function; + private final HashFunction hashFunction; public GuavaCSC(Cache guavaCache) { this(guavaCache, DEFAULT_HASH_FUNCTION); @@ -21,7 +25,7 @@ public GuavaCSC(Cache guavaCache) { public GuavaCSC(Cache guavaCache, HashFunction hashFunction) { super(); this.cache = guavaCache; - this.function = hashFunction; + this.hashFunction = hashFunction; } public GuavaCSC(Cache guavaCache, ClientSideCacheable cacheable) { @@ -31,7 +35,7 @@ public GuavaCSC(Cache guavaCache, ClientSideCacheable cacheable) { public GuavaCSC(Cache cache, HashFunction function, ClientSideCacheable cacheable) { super(cacheable); this.cache = cache; - this.function = function; + this.hashFunction = function; } @Override @@ -56,7 +60,7 @@ protected Object getValue(long hash) { @Override protected final long getHash(CommandObject command) { - Hasher hasher = function.newHasher(); + Hasher hasher = hashFunction.newHasher(); command.getArguments().forEach(raw -> hasher.putBytes(raw.getRaw())); hasher.putInt(command.getBuilder().hashCode()); return hasher.hash().asLong(); diff --git a/src/main/java/redis/clients/jedis/csc/StringWhiteListBlackListClientSideCacheable.java b/src/main/java/redis/clients/jedis/csc/util/StringWhiteListBlackListClientSideCacheable.java similarity index 93% rename from src/main/java/redis/clients/jedis/csc/StringWhiteListBlackListClientSideCacheable.java rename to src/main/java/redis/clients/jedis/csc/util/StringWhiteListBlackListClientSideCacheable.java index ee101bb2fc..5977d8b8bb 100644 --- a/src/main/java/redis/clients/jedis/csc/StringWhiteListBlackListClientSideCacheable.java +++ b/src/main/java/redis/clients/jedis/csc/util/StringWhiteListBlackListClientSideCacheable.java @@ -1,7 +1,8 @@ -package redis.clients.jedis.csc; +package redis.clients.jedis.csc.util; import java.util.Set; import redis.clients.jedis.commands.ProtocolCommand; +import redis.clients.jedis.csc.ClientSideCacheable; public class StringWhiteListBlackListClientSideCacheable implements ClientSideCacheable { diff --git a/src/main/java/redis/clients/jedis/util/JedisURIHelper.java b/src/main/java/redis/clients/jedis/util/JedisURIHelper.java index f536eae9b2..e8e62ae9b5 100644 --- a/src/main/java/redis/clients/jedis/util/JedisURIHelper.java +++ b/src/main/java/redis/clients/jedis/util/JedisURIHelper.java @@ -6,9 +6,9 @@ import redis.clients.jedis.Protocol; import redis.clients.jedis.RedisProtocol; -import redis.clients.jedis.csc.GuavaCSC; -import redis.clients.jedis.csc.CaffeineCSC; import redis.clients.jedis.csc.ClientSideCache; +import redis.clients.jedis.csc.util.GuavaCSC; +import redis.clients.jedis.csc.util.CaffeineCSC; public final class JedisURIHelper { diff --git a/src/test/java/redis/clients/jedis/csc/ClientSideCacheLibsTest.java b/src/test/java/redis/clients/jedis/csc/ClientSideCacheLibsTest.java index b9a2cf8d22..31589458f8 100644 --- a/src/test/java/redis/clients/jedis/csc/ClientSideCacheLibsTest.java +++ b/src/test/java/redis/clients/jedis/csc/ClientSideCacheLibsTest.java @@ -23,6 +23,8 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisClientConfig; import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.csc.util.CaffeineCSC; +import redis.clients.jedis.csc.util.GuavaCSC; public class ClientSideCacheLibsTest { diff --git a/src/test/java/redis/clients/jedis/csc/WhiteListBlackListClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/WhiteListBlackListClientSideCacheTest.java index ecb9802d31..d8f5174c26 100644 --- a/src/test/java/redis/clients/jedis/csc/WhiteListBlackListClientSideCacheTest.java +++ b/src/test/java/redis/clients/jedis/csc/WhiteListBlackListClientSideCacheTest.java @@ -21,6 +21,7 @@ import redis.clients.jedis.JedisClientConfig; import redis.clients.jedis.JedisPooled; import redis.clients.jedis.Protocol; +import redis.clients.jedis.csc.util.StringWhiteListBlackListClientSideCacheable; public class WhiteListBlackListClientSideCacheTest {