From 58e8cc2e41c6a540f43bff08e9976687e5961ac1 Mon Sep 17 00:00:00 2001 From: Dilyan Date: Wed, 8 Sep 2021 14:47:23 +0100 Subject: [PATCH 1/2] upgrade jedis to 3.7.0 --- build.sbt | 2 +- .../src/main/scala/scalacache/redis/RedisCacheBase.scala | 7 ++++--- .../main/scala/scalacache/redis/RedisClusterCache.scala | 8 ++++---- .../main/scala/scalacache/redis/SentinelRedisCache.scala | 6 +++--- .../main/scala/scalacache/redis/ShardedRedisCache.scala | 3 ++- .../scala/scalacache/redis/SentinelRedisCacheSpec.scala | 2 +- .../scala/scalacache/redis/ShardedRedisCacheSpec.scala | 5 +++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/build.sbt b/build.sbt index 4f686b66..b79126d7 100644 --- a/build.sbt +++ b/build.sbt @@ -67,7 +67,7 @@ lazy val memcached = createModule("memcached") lazy val redis = createModule("redis") .settings( libraryDependencies ++= Seq( - "redis.clients" % "jedis" % "2.10.2" + "redis.clients" % "jedis" % "3.7.0" ), coverageMinimum := 56, coverageFailOnMinimum := true diff --git a/modules/redis/src/main/scala/scalacache/redis/RedisCacheBase.scala b/modules/redis/src/main/scala/scalacache/redis/RedisCacheBase.scala index 5e3500b2..ec645edf 100644 --- a/modules/redis/src/main/scala/scalacache/redis/RedisCacheBase.scala +++ b/modules/redis/src/main/scala/scalacache/redis/RedisCacheBase.scala @@ -1,15 +1,16 @@ package scalacache.redis +import redis.clients.jedis.commands.BinaryJedisCommands +import redis.clients.jedis.util.Pool + import java.io.Closeable -import redis.clients.jedis._ -import redis.clients.util.Pool import scalacache.logging.Logger import scalacache.serialization.Codec import scalacache.{AbstractCache, CacheConfig} import scala.concurrent.duration._ -import cats.effect.{MonadCancelThrow, Resource} +import cats.effect.Resource import cats.syntax.all._ /** Contains implementations of all methods that can be implemented independent of the type of Redis client. This is diff --git a/modules/redis/src/main/scala/scalacache/redis/RedisClusterCache.scala b/modules/redis/src/main/scala/scalacache/redis/RedisClusterCache.scala index ed7504a6..22b5c727 100644 --- a/modules/redis/src/main/scala/scalacache/redis/RedisClusterCache.scala +++ b/modules/redis/src/main/scala/scalacache/redis/RedisClusterCache.scala @@ -1,7 +1,5 @@ package scalacache.redis -import redis.clients.jedis.JedisCluster -import redis.clients.jedis.exceptions.JedisClusterException import scalacache.logging.Logger import scalacache.redis.StringEnrichment._ import scalacache.serialization.Codec @@ -10,6 +8,8 @@ import scalacache.{AbstractCache, CacheConfig} import scala.concurrent.duration.{Duration, _} import cats.implicits._ import cats.effect.Sync +import redis.clients.jedis.JedisCluster +import redis.clients.jedis.exceptions.JedisClusterException class RedisClusterCache[F[_]: Sync, V](val jedisCluster: JedisCluster)(implicit val config: CacheConfig, @@ -48,9 +48,9 @@ class RedisClusterCache[F[_]: Sync, V](val jedisCluster: JedisCluster)(implicit logger.warn( s"Because Redis (pre 2.6.12) does not support sub-second expiry, TTL of $d will be rounded up to 1 second" ) - } *> F.delay(jedisCluster.setex(keyBytes, 1, valueBytes)) + } *> F.delay(jedisCluster.setex(keyBytes, 1L, valueBytes)) case Some(d) => - F.delay(jedisCluster.setex(keyBytes, d.toSeconds.toInt, valueBytes)) + F.delay(jedisCluster.setex(keyBytes, d.toSeconds, valueBytes)) } } diff --git a/modules/redis/src/main/scala/scalacache/redis/SentinelRedisCache.scala b/modules/redis/src/main/scala/scalacache/redis/SentinelRedisCache.scala index a0f1e667..6db4369d 100644 --- a/modules/redis/src/main/scala/scalacache/redis/SentinelRedisCache.scala +++ b/modules/redis/src/main/scala/scalacache/redis/SentinelRedisCache.scala @@ -1,6 +1,5 @@ package scalacache.redis -import org.apache.commons.pool2.impl.GenericObjectPoolConfig import redis.clients.jedis._ import scala.collection.JavaConverters._ @@ -8,6 +7,7 @@ import scalacache.CacheConfig import scalacache.serialization.Codec import cats.implicits._ import cats.effect.{MonadCancel, MonadCancelThrow, Sync} +import org.apache.commons.pool2.impl.GenericObjectPoolConfig /** Thin wrapper around Jedis that works with Redis Sentinel. */ @@ -43,7 +43,7 @@ object SentinelRedisCache { config: CacheConfig, codec: Codec[V] ): SentinelRedisCache[F, V] = - apply(new JedisSentinelPool(clusterName, sentinels.asJava, new GenericObjectPoolConfig, password)) + apply(new JedisSentinelPool(clusterName, sentinels.asJava, new GenericObjectPoolConfig[Jedis], password)) /** Create a `SentinelRedisCache` that uses a `JedisSentinelPool` with a custom pool config. * @@ -59,7 +59,7 @@ object SentinelRedisCache { def apply[F[_]: Sync: MonadCancelThrow, V]( clusterName: String, sentinels: Set[String], - poolConfig: GenericObjectPoolConfig, + poolConfig: GenericObjectPoolConfig[Jedis], password: String )(implicit config: CacheConfig, diff --git a/modules/redis/src/main/scala/scalacache/redis/ShardedRedisCache.scala b/modules/redis/src/main/scala/scalacache/redis/ShardedRedisCache.scala index b639f7b5..6ab44b2d 100644 --- a/modules/redis/src/main/scala/scalacache/redis/ShardedRedisCache.scala +++ b/modules/redis/src/main/scala/scalacache/redis/ShardedRedisCache.scala @@ -7,6 +7,7 @@ import scala.language.higherKinds import scalacache.CacheConfig import scalacache.serialization.Codec import cats.effect.{MonadCancel, MonadCancelThrow, Sync} +import org.apache.commons.pool2.impl.GenericObjectPoolConfig /** Thin wrapper around Jedis that works with sharded Redis. */ @@ -38,7 +39,7 @@ object ShardedRedisCache { val shards = hosts.map { case (host, port) => new JedisShardInfo(host, port) } - val pool = new ShardedJedisPool(new JedisPoolConfig(), shards.asJava) + val pool = new ShardedJedisPool(new GenericObjectPoolConfig[ShardedJedis], shards.asJava) apply(pool) } diff --git a/modules/redis/src/test/scala/scalacache/redis/SentinelRedisCacheSpec.scala b/modules/redis/src/test/scala/scalacache/redis/SentinelRedisCacheSpec.scala index 9dc31672..3ca99195 100644 --- a/modules/redis/src/test/scala/scalacache/redis/SentinelRedisCacheSpec.scala +++ b/modules/redis/src/test/scala/scalacache/redis/SentinelRedisCacheSpec.scala @@ -26,7 +26,7 @@ class SentinelRedisCacheSpec extends RedisCacheSpecBase { */ def assumingRedisSentinelIsRunning(f: (JedisSentinelPool, JedisClient) => Unit): Unit = { Try { - val jedisPool = new JedisSentinelPool("master", Set("127.0.0.1:26379").asJava, new GenericObjectPoolConfig) + val jedisPool = new JedisSentinelPool("master", Set("127.0.0.1:26379").asJava, new GenericObjectPoolConfig[Jedis]) val jedis = jedisPool.getResource() jedis.ping() (jedisPool, new JedisClient(jedis)) diff --git a/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala b/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala index a9bc2731..1d7fb2aa 100644 --- a/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala +++ b/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala @@ -1,12 +1,13 @@ package scalacache.redis -import redis.clients.jedis.{JedisPoolConfig, JedisShardInfo, ShardedJedisPool} +import redis.clients.jedis.{JedisShardInfo, ShardedJedisPool} import scalacache._ import scalacache.serialization.Codec import scala.collection.JavaConverters._ import scala.util.{Failure, Success, Try} import cats.effect.IO +import org.apache.commons.pool2.impl.GenericObjectPoolConfig class ShardedRedisCacheSpec extends RedisCacheSpecBase { @@ -27,7 +28,7 @@ class ShardedRedisCacheSpec extends RedisCacheSpecBase { val shard2 = new JedisShardInfo("localhost", 6380) val jedisPool = - new ShardedJedisPool(new JedisPoolConfig(), java.util.Arrays.asList(shard1, shard2)) + new ShardedJedisPool(new GenericObjectPoolConfig, java.util.Arrays.asList(shard1, shard2)) val jedis = jedisPool.getResource jedis.getAllShards.asScala.foreach(_.ping()) From 387bc1cf9b290039a5ac0c26b30f83c00b0e975a Mon Sep 17 00:00:00 2001 From: Dilyan Date: Tue, 21 Sep 2021 11:18:56 +0300 Subject: [PATCH 2/2] Fix 2.12 build - missing type info --- .../test/scala/scalacache/redis/ShardedRedisCacheSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala b/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala index 1d7fb2aa..c86dabbb 100644 --- a/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala +++ b/modules/redis/src/test/scala/scalacache/redis/ShardedRedisCacheSpec.scala @@ -1,6 +1,6 @@ package scalacache.redis -import redis.clients.jedis.{JedisShardInfo, ShardedJedisPool} +import redis.clients.jedis._ import scalacache._ import scalacache.serialization.Codec @@ -28,7 +28,7 @@ class ShardedRedisCacheSpec extends RedisCacheSpecBase { val shard2 = new JedisShardInfo("localhost", 6380) val jedisPool = - new ShardedJedisPool(new GenericObjectPoolConfig, java.util.Arrays.asList(shard1, shard2)) + new ShardedJedisPool(new GenericObjectPoolConfig[ShardedJedis], java.util.Arrays.asList(shard1, shard2)) val jedis = jedisPool.getResource jedis.getAllShards.asScala.foreach(_.ping())