From 0c95857915cc832080b23f85389d6333486b3025 Mon Sep 17 00:00:00 2001 From: atakavci Date: Wed, 11 Sep 2024 11:57:05 +0300 Subject: [PATCH 1/9] checking server version for CSC --- .../java/redis/clients/jedis/Connection.java | 85 +++++++++++-------- .../clients/jedis/csc/AbstractCache.java | 11 ++- .../java/redis/clients/jedis/csc/Cache.java | 5 ++ .../clients/jedis/csc/CacheConnection.java | 10 +++ .../redis/clients/jedis/util/Version.java | 40 +++++++++ .../redis/clients/jedis/util/VersionTest.java | 30 +++++++ 6 files changed, 141 insertions(+), 40 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/util/Version.java create mode 100644 src/test/java/redis/clients/jedis/util/VersionTest.java diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 68eaee3b74..37add8e36b 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.function.Supplier; import redis.clients.jedis.Protocol.Command; @@ -41,6 +42,8 @@ public class Connection implements Closeable { private boolean broken = false; private boolean strValActive; private String strVal; + protected String server; + protected String version; public Connection() { this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT); @@ -453,12 +456,12 @@ protected void initializeFromClientConfig(final JedisClientConfig config) { final RedisCredentialsProvider redisCredentialsProvider = (RedisCredentialsProvider) credentialsProvider; try { redisCredentialsProvider.prepare(); - helloOrAuth(protocol, redisCredentialsProvider.get()); + helloAndAuth(protocol, redisCredentialsProvider.get()); } finally { redisCredentialsProvider.cleanUp(); } } else { - helloOrAuth(protocol, credentialsProvider != null ? credentialsProvider.get() + helloAndAuth(protocol, credentialsProvider != null ? credentialsProvider.get() : new DefaultRedisCredentials(config.getUser(), config.getPassword())); } @@ -517,50 +520,60 @@ protected void initializeFromClientConfig(final JedisClientConfig config) { } } - private void helloOrAuth(final RedisProtocol protocol, final RedisCredentials credentials) { - - if (credentials == null || credentials.getPassword() == null) { - if (protocol != null) { - sendCommand(Command.HELLO, encode(protocol.version())); - getOne(); + private void helloAndAuth(final RedisProtocol protocol, final RedisCredentials credentials) { + Object helloResp = null; + if (protocol != null && credentials != null && credentials.getUser() != null) { + byte[] rawPass = encodeToBytes(credentials.getPassword()); + try { + sendCommand(Command.HELLO, encode(protocol.version()), Keyword.AUTH.getRaw(), encode(credentials.getUser()), rawPass); + helloResp = getOne(); + } finally { + Arrays.fill(rawPass, (byte) 0); // clear sensitive data } - return; + } else { + auth(credentials); + helloResp = hello(protocol); } + Map helloResult = BuilderFactory.ENCODED_OBJECT_MAP.build(helloResp); + server = (String) helloResult.get("server"); + version = (String) helloResult.get("version"); - // Source: https://stackoverflow.com/a/9670279/4021802 - ByteBuffer passBuf = Protocol.CHARSET.encode(CharBuffer.wrap(credentials.getPassword())); - byte[] rawPass = Arrays.copyOfRange(passBuf.array(), passBuf.position(), passBuf.limit()); - Arrays.fill(passBuf.array(), (byte) 0); // clear sensitive data + // clearing 'char[] credentials.getPassword()' should be + // handled in RedisCredentialsProvider.cleanUp() + } + private void auth(RedisCredentials credentials) { + if (credentials == null || credentials.getPassword() == null) { + return; + } + byte[] rawPass = encodeToBytes(credentials.getPassword()); try { - /// actual HELLO or AUTH --> - if (protocol != null) { - if (credentials.getUser() != null) { - sendCommand(Command.HELLO, encode(protocol.version()), - Keyword.AUTH.getRaw(), encode(credentials.getUser()), rawPass); - getOne(); // Map - } else { - sendCommand(Command.AUTH, rawPass); - getStatusCodeReply(); // OK - sendCommand(Command.HELLO, encode(protocol.version())); - getOne(); // Map - } - } else { // protocol == null - if (credentials.getUser() != null) { - sendCommand(Command.AUTH, encode(credentials.getUser()), rawPass); - } else { - sendCommand(Command.AUTH, rawPass); - } - getStatusCodeReply(); // OK + if (credentials.getUser() == null) { + sendCommand(Command.AUTH, rawPass); + } else { + sendCommand(Command.AUTH, encode(credentials.getUser()), rawPass); } - /// <-- actual HELLO or AUTH } finally { - Arrays.fill(rawPass, (byte) 0); // clear sensitive data } + getStatusCodeReply(); + } - // clearing 'char[] credentials.getPassword()' should be - // handled in RedisCredentialsProvider.cleanUp() + private Object hello(RedisProtocol protocol) { + if (protocol == null) { + sendCommand(Command.HELLO); + } else { + sendCommand(Command.HELLO, encode(protocol.version())); + } + return getOne(); + } + + private byte[] encodeToBytes(char[] chars) { + // Source: https://stackoverflow.com/a/9670279/4021802 + ByteBuffer passBuf = Protocol.CHARSET.encode(CharBuffer.wrap(chars)); + byte[] rawPass = Arrays.copyOfRange(passBuf.array(), passBuf.position(), passBuf.limit()); + Arrays.fill(passBuf.array(), (byte) 0); // clear sensitive data + return rawPass; } public String select(final int index) { diff --git a/src/main/java/redis/clients/jedis/csc/AbstractCache.java b/src/main/java/redis/clients/jedis/csc/AbstractCache.java index fc936b5baf..0e5071850a 100644 --- a/src/main/java/redis/clients/jedis/csc/AbstractCache.java +++ b/src/main/java/redis/clients/jedis/csc/AbstractCache.java @@ -146,8 +146,7 @@ public List deleteByRedisKeys(List keys) { } lock.lock(); try { - return ((List) keys).stream() - .map(this::deleteByRedisKey).flatMap(List::stream).collect(Collectors.toList()); + return ((List) keys).stream().map(this::deleteByRedisKey).flatMap(List::stream).collect(Collectors.toList()); } finally { lock.unlock(); } @@ -193,6 +192,10 @@ public CacheStats getAndResetStats() { return result; } + @Override + public boolean compatibilityMode() { + return false; + } // End of Cache interface methods // abstract methods to be implemented by the concrete classes @@ -216,8 +219,8 @@ private ByteBuffer makeKeyForRedisKeysToCacheKeys(Object key) { } else if (key instanceof String) { return makeKeyForRedisKeysToCacheKeys(SafeEncoder.encode((String) key)); } else { - throw new IllegalArgumentException(key.getClass().getSimpleName() + " is not supported." - + " Value: \"" + String.valueOf(key) + "\"."); + throw new IllegalArgumentException( + key.getClass().getSimpleName() + " is not supported." + " Value: \"" + String.valueOf(key) + "\"."); } } diff --git a/src/main/java/redis/clients/jedis/csc/Cache.java b/src/main/java/redis/clients/jedis/csc/Cache.java index 49413bc0de..0bf4592b59 100644 --- a/src/main/java/redis/clients/jedis/csc/Cache.java +++ b/src/main/java/redis/clients/jedis/csc/Cache.java @@ -105,4 +105,9 @@ public interface Cache { * @return The statistics of the cache */ CacheStats getAndResetStats(); + + /** + * @return The compatibility of cache against different Redis versions + */ + boolean compatibilityMode(); } diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index c19dd319ec..29dade8d78 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -11,11 +11,14 @@ import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.RedisInputStream; +import redis.clients.jedis.util.Version; public class CacheConnection extends Connection { private final Cache cache; private ReentrantLock lock; + private static final String REDIS = "redis"; + private static final String MIN_REDIS_VERSION = "7.4"; public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig clientConfig, Cache cache) { super(socketFactory, clientConfig); @@ -23,6 +26,13 @@ public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig if (protocol != RedisProtocol.RESP3) { throw new JedisException("Client side caching is only supported with RESP3."); } + if (!cache.compatibilityMode()) { + Version current = new Version(version); + Version required = new Version(MIN_REDIS_VERSION); + if (!REDIS.equals(server) || current.compareTo(required) < 1) { + throw new JedisException(String.format("Client side caching is only supported with 'Redis %s' or later.", MIN_REDIS_VERSION)); + } + } this.cache = Objects.requireNonNull(cache); initializeClientSideCache(); } diff --git a/src/main/java/redis/clients/jedis/util/Version.java b/src/main/java/redis/clients/jedis/util/Version.java new file mode 100644 index 0000000000..9748a4b422 --- /dev/null +++ b/src/main/java/redis/clients/jedis/util/Version.java @@ -0,0 +1,40 @@ +package redis.clients.jedis.util; + +import java.util.Arrays; + +public class Version implements Comparable { + + private String version; + private Integer[] numbers; + + public Version(String version) { + if (version == null) throw new IllegalArgumentException("Version can not be null"); + this.version = version; + this.numbers = Arrays.stream(version.split("\\.")).map(n -> Integer.parseInt(n)).toArray(Integer[]::new); + } + + @Override + public int compareTo(Version other) { + int max = Math.max(this.numbers.length, other.numbers.length); + for (int i = 0; i < max; i++) { + int thisNumber = this.numbers.length > i ? this.numbers[i]:0; + int otherNumber = other.numbers.length > i ? other.numbers[i]:0; + if (thisNumber < otherNumber) return -1; + if (thisNumber > otherNumber) return 1; + } + return 0; + } + + public final String get() { + return this.version; + } + + @Override + public boolean equals(Object that) { + if (this == that) return true; + if (that == null) return false; + if (this.getClass() != that.getClass()) return false; + return this.compareTo((Version) that) == 0; + } + +} diff --git a/src/test/java/redis/clients/jedis/util/VersionTest.java b/src/test/java/redis/clients/jedis/util/VersionTest.java new file mode 100644 index 0000000000..441fc73860 --- /dev/null +++ b/src/test/java/redis/clients/jedis/util/VersionTest.java @@ -0,0 +1,30 @@ +package redis.clients.jedis.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class VersionTest { + + @Test + public void compareSameVersions() { + Version a = new Version("5.2.4"); + Version b = new Version("5.2.4"); + assertEquals(a, b); + + Version c = new Version("5.2.0.0"); + Version d = new Version("5.2"); + assertEquals(a, b); + } + + @Test + public void compareDifferentVersions() { + Version a = new Version("5.2.4"); + Version b = new Version("5.1.4"); + assertEquals(1, a.compareTo(b)); + + Version c = new Version("5.2.4"); + Version d = new Version("5.2.5"); + assertEquals(-1, c.compareTo(d)); + } +} From d5010e45f97d57dab936fa80d9ad42e7f877444e Mon Sep 17 00:00:00 2001 From: atakavci Date: Wed, 11 Sep 2024 12:02:12 +0300 Subject: [PATCH 2/9] fix format change --- src/main/java/redis/clients/jedis/csc/AbstractCache.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/csc/AbstractCache.java b/src/main/java/redis/clients/jedis/csc/AbstractCache.java index 0e5071850a..84b4d2ef81 100644 --- a/src/main/java/redis/clients/jedis/csc/AbstractCache.java +++ b/src/main/java/redis/clients/jedis/csc/AbstractCache.java @@ -146,7 +146,8 @@ public List deleteByRedisKeys(List keys) { } lock.lock(); try { - return ((List) keys).stream().map(this::deleteByRedisKey).flatMap(List::stream).collect(Collectors.toList()); + return ((List) keys).stream() + .map(this::deleteByRedisKey).flatMap(List::stream).collect(Collectors.toList()); } finally { lock.unlock(); } @@ -219,8 +220,8 @@ private ByteBuffer makeKeyForRedisKeysToCacheKeys(Object key) { } else if (key instanceof String) { return makeKeyForRedisKeysToCacheKeys(SafeEncoder.encode((String) key)); } else { - throw new IllegalArgumentException( - key.getClass().getSimpleName() + " is not supported." + " Value: \"" + String.valueOf(key) + "\"."); + throw new IllegalArgumentException(key.getClass().getSimpleName() + " is not supported." + + " Value: \"" + String.valueOf(key) + "\"."); } } From 2e7021bc63eef9b014c412be31beebebdb51dede Mon Sep 17 00:00:00 2001 From: atakavci Date: Wed, 11 Sep 2024 14:59:45 +0300 Subject: [PATCH 3/9] fix noauth hello exception in integration tests --- .../java/redis/clients/jedis/Connection.java | 26 ++++++++----------- .../clients/jedis/csc/CacheConnection.java | 10 +++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 37add8e36b..2860866c6e 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -521,22 +521,22 @@ protected void initializeFromClientConfig(final JedisClientConfig config) { } private void helloAndAuth(final RedisProtocol protocol, final RedisCredentials credentials) { - Object helloResp = null; + Map helloResult = null; if (protocol != null && credentials != null && credentials.getUser() != null) { byte[] rawPass = encodeToBytes(credentials.getPassword()); try { - sendCommand(Command.HELLO, encode(protocol.version()), Keyword.AUTH.getRaw(), encode(credentials.getUser()), rawPass); - helloResp = getOne(); + helloResult = hello(encode(protocol.version()), Keyword.AUTH.getRaw(), encode(credentials.getUser()), rawPass); } finally { Arrays.fill(rawPass, (byte) 0); // clear sensitive data } } else { auth(credentials); - helloResp = hello(protocol); + helloResult = protocol == null ? null : hello(encode(protocol.version())); + } + if (helloResult != null) { + server = (String) helloResult.get("server"); + version = (String) helloResult.get("version"); } - Map helloResult = BuilderFactory.ENCODED_OBJECT_MAP.build(helloResp); - server = (String) helloResult.get("server"); - version = (String) helloResult.get("version"); // clearing 'char[] credentials.getPassword()' should be // handled in RedisCredentialsProvider.cleanUp() @@ -559,16 +559,12 @@ private void auth(RedisCredentials credentials) { getStatusCodeReply(); } - private Object hello(RedisProtocol protocol) { - if (protocol == null) { - sendCommand(Command.HELLO); - } else { - sendCommand(Command.HELLO, encode(protocol.version())); - } - return getOne(); + protected Map hello(byte[]... args) { + sendCommand(Command.HELLO, args); + return BuilderFactory.ENCODED_OBJECT_MAP.build(getOne()); } - private byte[] encodeToBytes(char[] chars) { + protected byte[] encodeToBytes(char[] chars) { // Source: https://stackoverflow.com/a/9670279/4021802 ByteBuffer passBuf = Protocol.CHARSET.encode(CharBuffer.wrap(chars)); byte[] rawPass = Arrays.copyOfRange(passBuf.array(), passBuf.position(), passBuf.limit()); diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index 29dade8d78..9f78178d3b 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -1,5 +1,8 @@ package redis.clients.jedis.csc; +import static redis.clients.jedis.util.SafeEncoder.encode; + +import java.util.Map; import java.util.Objects; import java.util.concurrent.locks.ReentrantLock; @@ -27,6 +30,13 @@ public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig throw new JedisException("Client side caching is only supported with RESP3."); } if (!cache.compatibilityMode()) { + if (server == null || version == null) { + Map helloResult = hello(encode(protocol.version())); + if (helloResult != null) { + server = (String) helloResult.get("server"); + version = (String) helloResult.get("version"); + } + } Version current = new Version(version); Version required = new Version(MIN_REDIS_VERSION); if (!REDIS.equals(server) || current.compareTo(required) < 1) { From 79e6ced07b6c66fe75710e6b0bd9e210cf60e304 Mon Sep 17 00:00:00 2001 From: atakavci Date: Wed, 11 Sep 2024 15:01:40 +0300 Subject: [PATCH 4/9] fix version check --- src/main/java/redis/clients/jedis/csc/CacheConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index 9f78178d3b..b6e8c8268f 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -39,7 +39,7 @@ public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig } Version current = new Version(version); Version required = new Version(MIN_REDIS_VERSION); - if (!REDIS.equals(server) || current.compareTo(required) < 1) { + if (!REDIS.equals(server) || current.compareTo(required) < 0) { throw new JedisException(String.format("Client side caching is only supported with 'Redis %s' or later.", MIN_REDIS_VERSION)); } } From 4c65d5a99e20367ac4676df539533d1a3e570921 Mon Sep 17 00:00:00 2001 From: atakavci Date: Thu, 12 Sep 2024 14:48:07 +0300 Subject: [PATCH 5/9] remove redundant check --- src/main/java/redis/clients/jedis/csc/CacheConnection.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index b6e8c8268f..d878a1fce6 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -30,13 +30,6 @@ public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig throw new JedisException("Client side caching is only supported with RESP3."); } if (!cache.compatibilityMode()) { - if (server == null || version == null) { - Map helloResult = hello(encode(protocol.version())); - if (helloResult != null) { - server = (String) helloResult.get("server"); - version = (String) helloResult.get("version"); - } - } Version current = new Version(version); Version required = new Version(MIN_REDIS_VERSION); if (!REDIS.equals(server) || current.compareTo(required) < 0) { From 3de89ade318e911b28bcc12853772b40a0b4bcf6 Mon Sep 17 00:00:00 2001 From: atakavci Date: Thu, 12 Sep 2024 15:00:18 +0300 Subject: [PATCH 6/9] remove unused imports --- src/main/java/redis/clients/jedis/csc/CacheConnection.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index d878a1fce6..90ef1695fa 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -1,8 +1,5 @@ package redis.clients.jedis.csc; -import static redis.clients.jedis.util.SafeEncoder.encode; - -import java.util.Map; import java.util.Objects; import java.util.concurrent.locks.ReentrantLock; From a81c04feec7d04c83d6e275548bb2da79a126b8f Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 16 Sep 2024 12:33:04 +0300 Subject: [PATCH 7/9] 'toString' for Version --- src/main/java/redis/clients/jedis/util/Version.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/util/Version.java b/src/main/java/redis/clients/jedis/util/Version.java index 9748a4b422..f5f9bc620f 100644 --- a/src/main/java/redis/clients/jedis/util/Version.java +++ b/src/main/java/redis/clients/jedis/util/Version.java @@ -25,7 +25,8 @@ public int compareTo(Version other) { return 0; } - public final String get() { + @Override + public String toString() { return this.version; } From 8a21ec3fc1627e029ed8ea16c5ffed3032db7937 Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 16 Sep 2024 13:52:16 +0300 Subject: [PATCH 8/9] rename to RedisVersion --- .../redis/clients/jedis/csc/CacheConnection.java | 6 +++--- .../util/{Version.java => RedisVersion.java} | 8 ++++---- .../redis/clients/jedis/util/VersionTest.java | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/main/java/redis/clients/jedis/util/{Version.java => RedisVersion.java} (83%) diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index 90ef1695fa..06fe965ad2 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -11,7 +11,7 @@ import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.RedisInputStream; -import redis.clients.jedis.util.Version; +import redis.clients.jedis.util.RedisVersion; public class CacheConnection extends Connection { @@ -27,8 +27,8 @@ public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig throw new JedisException("Client side caching is only supported with RESP3."); } if (!cache.compatibilityMode()) { - Version current = new Version(version); - Version required = new Version(MIN_REDIS_VERSION); + RedisVersion current = new RedisVersion(version); + RedisVersion required = new RedisVersion(MIN_REDIS_VERSION); if (!REDIS.equals(server) || current.compareTo(required) < 0) { throw new JedisException(String.format("Client side caching is only supported with 'Redis %s' or later.", MIN_REDIS_VERSION)); } diff --git a/src/main/java/redis/clients/jedis/util/Version.java b/src/main/java/redis/clients/jedis/util/RedisVersion.java similarity index 83% rename from src/main/java/redis/clients/jedis/util/Version.java rename to src/main/java/redis/clients/jedis/util/RedisVersion.java index f5f9bc620f..629e7fbb7a 100644 --- a/src/main/java/redis/clients/jedis/util/Version.java +++ b/src/main/java/redis/clients/jedis/util/RedisVersion.java @@ -2,19 +2,19 @@ import java.util.Arrays; -public class Version implements Comparable { +public class RedisVersion implements Comparable { private String version; private Integer[] numbers; - public Version(String version) { + public RedisVersion(String version) { if (version == null) throw new IllegalArgumentException("Version can not be null"); this.version = version; this.numbers = Arrays.stream(version.split("\\.")).map(n -> Integer.parseInt(n)).toArray(Integer[]::new); } @Override - public int compareTo(Version other) { + public int compareTo(RedisVersion other) { int max = Math.max(this.numbers.length, other.numbers.length); for (int i = 0; i < max; i++) { int thisNumber = this.numbers.length > i ? this.numbers[i]:0; @@ -35,7 +35,7 @@ public boolean equals(Object that) { if (this == that) return true; if (that == null) return false; if (this.getClass() != that.getClass()) return false; - return this.compareTo((Version) that) == 0; + return this.compareTo((RedisVersion) that) == 0; } } diff --git a/src/test/java/redis/clients/jedis/util/VersionTest.java b/src/test/java/redis/clients/jedis/util/VersionTest.java index 441fc73860..c7475fb6bd 100644 --- a/src/test/java/redis/clients/jedis/util/VersionTest.java +++ b/src/test/java/redis/clients/jedis/util/VersionTest.java @@ -8,23 +8,23 @@ public class VersionTest { @Test public void compareSameVersions() { - Version a = new Version("5.2.4"); - Version b = new Version("5.2.4"); + RedisVersion a = new RedisVersion("5.2.4"); + RedisVersion b = new RedisVersion("5.2.4"); assertEquals(a, b); - Version c = new Version("5.2.0.0"); - Version d = new Version("5.2"); + RedisVersion c = new RedisVersion("5.2.0.0"); + RedisVersion d = new RedisVersion("5.2"); assertEquals(a, b); } @Test public void compareDifferentVersions() { - Version a = new Version("5.2.4"); - Version b = new Version("5.1.4"); + RedisVersion a = new RedisVersion("5.2.4"); + RedisVersion b = new RedisVersion("5.1.4"); assertEquals(1, a.compareTo(b)); - Version c = new Version("5.2.4"); - Version d = new Version("5.2.5"); + RedisVersion c = new RedisVersion("5.2.4"); + RedisVersion d = new RedisVersion("5.2.5"); assertEquals(-1, c.compareTo(d)); } } From d6610536cc8bdc869de7776c5c6c6b081a18d994 Mon Sep 17 00:00:00 2001 From: atakavci Date: Tue, 17 Sep 2024 11:50:26 +0300 Subject: [PATCH 9/9] moving RedisVersion package --- src/main/java/redis/clients/jedis/csc/CacheConnection.java | 1 - .../java/redis/clients/jedis/{util => csc}/RedisVersion.java | 4 ++-- .../java/redis/clients/jedis/{util => csc}/VersionTest.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) rename src/main/java/redis/clients/jedis/{util => csc}/RedisVersion.java (92%) rename src/test/java/redis/clients/jedis/{util => csc}/VersionTest.java (95%) diff --git a/src/main/java/redis/clients/jedis/csc/CacheConnection.java b/src/main/java/redis/clients/jedis/csc/CacheConnection.java index 06fe965ad2..f157d95a94 100644 --- a/src/main/java/redis/clients/jedis/csc/CacheConnection.java +++ b/src/main/java/redis/clients/jedis/csc/CacheConnection.java @@ -11,7 +11,6 @@ import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.RedisInputStream; -import redis.clients.jedis.util.RedisVersion; public class CacheConnection extends Connection { diff --git a/src/main/java/redis/clients/jedis/util/RedisVersion.java b/src/main/java/redis/clients/jedis/csc/RedisVersion.java similarity index 92% rename from src/main/java/redis/clients/jedis/util/RedisVersion.java rename to src/main/java/redis/clients/jedis/csc/RedisVersion.java index 629e7fbb7a..2daf6393c7 100644 --- a/src/main/java/redis/clients/jedis/util/RedisVersion.java +++ b/src/main/java/redis/clients/jedis/csc/RedisVersion.java @@ -1,8 +1,8 @@ -package redis.clients.jedis.util; +package redis.clients.jedis.csc; import java.util.Arrays; -public class RedisVersion implements Comparable { +class RedisVersion implements Comparable { private String version; private Integer[] numbers; diff --git a/src/test/java/redis/clients/jedis/util/VersionTest.java b/src/test/java/redis/clients/jedis/csc/VersionTest.java similarity index 95% rename from src/test/java/redis/clients/jedis/util/VersionTest.java rename to src/test/java/redis/clients/jedis/csc/VersionTest.java index c7475fb6bd..b154e88a05 100644 --- a/src/test/java/redis/clients/jedis/util/VersionTest.java +++ b/src/test/java/redis/clients/jedis/csc/VersionTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.util; +package redis.clients.jedis.csc; import static org.junit.Assert.assertEquals;