Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for KEEPTTL option in SET command #714

Merged
merged 3 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ object effects {

/** Set Expiration in Seconds */
case class Ex(duration: FiniteDuration) extends Ttl

/** Set KeepTtl */
case object Keep extends Ttl
}
}
case class SetArgs(existence: Option[SetArg.Existence], ttl: Option[SetArg.Ttl])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ private[redis4cats] class BaseRedis[F[_]: FutureLift: MonadThrow: Log, K, V](
setArgs.ttl.foreach {
case SetArg.Ttl.Px(d) => jSetArgs.px(d.toMillis)
case SetArg.Ttl.Ex(d) => jSetArgs.ex(d.toSeconds)
case SetArg.Ttl.Keep => jSetArgs.keepttl()
}

async.flatMap(_.set(key, value, jSetArgs).futureLift.map(_ == "OK"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ trait TestScenarios { self: FunSuite =>
j <- redis.expire("_not_existing_key_", 50.millis)
_ <- IO(assertEquals(j, false))
_ <- redis.del("f1")
k <- redis.set("k", "", SetArgs(SetArg.Ttl.Ex(10.seconds)))
_ <- IO(assertEquals(k, true))
kTtl <- redis.ttl("k")
_ <- IO(assert(kTtl.nonEmpty))
_ <- redis.set("k", "v", SetArgs(SetArg.Ttl.Keep))
kv <- redis.get("k")
_ <- IO(assertEquals(kv, Some("v")))
kTtl2 <- redis.ttl("k")
_ <- IO(assert(kTtl2.nonEmpty))
_ <- redis.del("k")
} yield ()
}

Expand Down