Skip to content

Commit

Permalink
fixing return for pttl to interpreted as millis (#819)
Browse files Browse the repository at this point in the history
Co-authored-by: Shawn Garner <[email protected]>
  • Loading branch information
BusyByte and Shawn Garner authored Sep 28, 2023
1 parent eabc336 commit 115c160
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,17 @@ private[redis4cats] class BaseRedis[F[_]: FutureLift: MonadThrow: Log, K, V](
case d => FiniteDuration(d, TimeUnit.SECONDS).some
}

private def toFiniteDuration(duration: java.lang.Long): Option[FiniteDuration] =
private def toFiniteDuration(units: TimeUnit)(duration: java.lang.Long): Option[FiniteDuration] =
duration match {
case d if d < 0 => none[FiniteDuration]
case d => FiniteDuration(d, TimeUnit.SECONDS).some
case d => FiniteDuration(d, units).some
}

override def ttl(key: K): F[Option[FiniteDuration]] =
async.flatMap(_.ttl(key).futureLift.map(toFiniteDuration))
async.flatMap(_.ttl(key).futureLift.map(toFiniteDuration(TimeUnit.SECONDS)))

override def pttl(key: K): F[Option[FiniteDuration]] =
async.flatMap(_.pttl(key).futureLift.map(toFiniteDuration))
async.flatMap(_.pttl(key).futureLift.map(toFiniteDuration(TimeUnit.MILLISECONDS)))

override def scan: F[KeyScanCursor[K]] =
async.flatMap(_.scan().futureLift.map(KeyScanCursor[K]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ trait TestScenarios { self: FunSuite =>
_ <- IO(assert(c.nonEmpty))
d <- redis.pttl("f1")
_ <- IO(assert(d.nonEmpty))
_ <- IO(assert(d.exists(_ <= 10.seconds)))
_ <- redis.set("f2", "yay")
i <- redis.expire("f2", 50.millis)
_ <- IO(assertEquals(i, true))
Expand Down

0 comments on commit 115c160

Please sign in to comment.