Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
drmarjanovic committed Sep 26, 2024
1 parent e609e20 commit 7fdda22
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object ContributorsCache {
ZIO
.fromOption(NonEmptyChunk.fromChunk(contributors))
.map(Contributors(_).toJson)
.flatMap(data => redis.set(repository.key, data, expireAt = Some(SetExpire.Seconds(60))).orDie)
.flatMap(data => redis.set(repository.key, data, expireAt = Some(SetExpire.SetExpireSeconds(60))).orDie)
.ignore

private def read(repository: Repository): IO[ApiError, Contributors] =
Expand Down
4 changes: 2 additions & 2 deletions modules/redis-it/src/test/scala/zio/redis/KeysSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ trait KeysSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(1000)))
_ <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireMilliseconds(1000)))
ttl <- redis.ttl(key).either
} yield assert(ttl)(isRight)
} @@ flaky,
Expand All @@ -260,7 +260,7 @@ trait KeysSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(1000)))
_ <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireMilliseconds(1000)))
pTtl <- redis.pTtl(key).either
} yield assert(pTtl)(isRight)
} @@ flaky,
Expand Down
31 changes: 16 additions & 15 deletions modules/redis-it/src/test/scala/zio/redis/StringsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1457,23 +1457,23 @@ trait StringsSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
result <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(1)))
result <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(1)))
} yield assert(result)(isTrue)
},
test("new value with ttl 100 milliseconds") {
for {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
result <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(100)))
result <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireMilliseconds(100)))
} yield assert(result)(isTrue)
},
test("error when negative ttl") {
for {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
result <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(-1))).either
result <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireMilliseconds(-1))).either
} yield assert(result)(isLeft(isSubtype[ProtocolError](anything)))
},
test("new value with SetNew parameter") {
Expand Down Expand Up @@ -1533,7 +1533,7 @@ trait StringsSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, "value", expireAt = Some(SetExpire.Seconds(1)))
_ <- redis.set(key, "value", expireAt = Some(SetExpire.SetExpireSeconds(1)))
result <- redis.set(key, value, expireAt = Some(SetExpire.KeepTtl))
} yield assert(result)(isTrue)
}
Expand Down Expand Up @@ -1585,7 +1585,7 @@ trait StringsSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(1)))
_ <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(1)))
existsBefore <- redis.exists(key)
fiber <- ZIO.sleep(1010.millis).fork <* TestClock.adjust(1010.millis)
_ <- fiber.join
Expand All @@ -1598,7 +1598,7 @@ trait StringsSpec extends IntegrationSpec {
key <- uuid
value <- uuid
_ <- redis.set(key, "value")
_ <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(1)))
_ <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(1)))
existsBefore <- redis.exists(key)
fiber <- ZIO.sleep(1010.millis).fork <* TestClock.adjust(1010.millis)
_ <- fiber.join
Expand All @@ -1611,7 +1611,7 @@ trait StringsSpec extends IntegrationSpec {
key <- uuid
value <- uuid
_ <- redis.sAdd(key, "a")
_ <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(1)))
_ <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(1)))
existsBefore <- redis.exists(key)
fiber <- ZIO.sleep(1010.millis).fork <* TestClock.adjust(1010.millis)
_ <- fiber.join
Expand All @@ -1623,15 +1623,15 @@ trait StringsSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
result <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(0))).either
result <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(0))).either
} yield assert(result)(isLeft(isSubtype[ProtocolError](anything)))
},
test("error when negative ttl") {
for {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
result <- redis.set(key, value, expireAt = Some(SetExpire.Seconds(-1))).either
result <- redis.set(key, value, expireAt = Some(SetExpire.SetExpireSeconds(-1))).either
} yield assert(result)(isLeft(isSubtype[ProtocolError](anything)))
}
),
Expand Down Expand Up @@ -1735,7 +1735,7 @@ trait StringsSpec extends IntegrationSpec {
key <- uuid
value <- uuid
_ <- redis.set(key, value)
exists <- redis.getEx(key, GetExpire.Seconds(1)).returning[String]
exists <- redis.getEx(key, GetExpire.GetExpireSeconds(1)).returning[String]
fiber <- ZIO.sleep(1020.millis).fork <* TestClock.adjust(1020.millis)
_ <- fiber.join
res <- redis.get(key).returning[String]
Expand All @@ -1747,7 +1747,7 @@ trait StringsSpec extends IntegrationSpec {
key <- uuid
value <- uuid
_ <- redis.set(key, value)
exists <- redis.getEx(key, GetExpire.Milliseconds(10)).returning[String]
exists <- redis.getEx(key, GetExpire.GetExpireMilliseconds(10)).returning[String]
fiber <- ZIO.sleep(20.millis).fork <* TestClock.adjust(20.millis)
_ <- fiber.join
res <- redis.get(key).returning[String]
Expand All @@ -1760,7 +1760,7 @@ trait StringsSpec extends IntegrationSpec {
value <- uuid
_ <- redis.set(key, value)
expiresAt <- Clock.instant.map(_.plusMillis(10.millis.toMillis))
exists <- redis.getEx(key, GetExpire.UnixTimeSeconds(expiresAt.getEpochSecond)).returning[String]
exists <- redis.getEx(key, GetExpire.GetExpireUnixTimeSeconds(expiresAt.getEpochSecond)).returning[String]
fiber <- ZIO.sleep(20.millis).fork <* TestClock.adjust(20.millis)
_ <- fiber.join
res <- redis.get(key).returning[String]
Expand All @@ -1773,7 +1773,8 @@ trait StringsSpec extends IntegrationSpec {
value <- uuid
_ <- redis.set(key, value)
expiresAt <- Clock.instant.map(_.plusMillis(10.millis.toMillis))
exists <- redis.getEx(key, GetExpire.UnixTimeMilliseconds(expiresAt.toEpochMilli)).returning[String]
exists <-
redis.getEx(key, GetExpire.GetExpireUnixTimeMilliseconds(expiresAt.toEpochMilli)).returning[String]
fiber <- ZIO.sleep(20.millis).fork <* TestClock.adjust(20.millis)
_ <- fiber.join
res <- redis.get(key).returning[String]
Expand All @@ -1786,8 +1787,8 @@ trait StringsSpec extends IntegrationSpec {
value <- uuid
_ <- redis.set(key, value)
expiresAt <- Clock.instant.map(_.plusMillis(10.millis.toMillis))
res <- redis.getEx(value, GetExpire.UnixTimeMilliseconds(expiresAt.toEpochMilli)).returning[String]
res2 <- redis.getEx(value, GetExpire.Milliseconds(10)).returning[String]
res <- redis.getEx(value, GetExpire.GetExpireUnixTimeMilliseconds(expiresAt.toEpochMilli)).returning[String]
res2 <- redis.getEx(value, GetExpire.GetExpireMilliseconds(10)).returning[String]
} yield assert(res)(isNone) && assert(res2)(isNone)
} @@ flaky
),
Expand Down
20 changes: 10 additions & 10 deletions modules/redis/src/main/scala/zio/redis/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,27 @@ object Input {
final case class GetExInput[K: BinaryCodec]() extends Input[(K, GetExpire)] {
def encode(data: (K, GetExpire)): RespCommand =
data match {
case (key, GetExpire.Milliseconds(milliseconds)) =>
case (key, GetExpire.GetExpireMilliseconds(milliseconds)) =>
RespCommand(
RespCommandArgument.Key(key),
RespCommandArgument.Literal("PX"),
RespCommandArgument.Value(milliseconds.toString)
)
case (key, GetExpire.Persist) =>
case (key, GetExpire.Persist) =>
RespCommand(RespCommandArgument.Key(key), RespCommandArgument.Literal("PERSIST"))
case (key, GetExpire.Seconds(seconds)) =>
case (key, GetExpire.GetExpireSeconds(seconds)) =>
RespCommand(
RespCommandArgument.Key(key),
RespCommandArgument.Literal("EX"),
RespCommandArgument.Value(seconds.toString)
)
case (key, GetExpire.UnixTimeMilliseconds(milliseconds)) =>
case (key, GetExpire.GetExpireUnixTimeMilliseconds(milliseconds)) =>
RespCommand(
RespCommandArgument.Key(key),
RespCommandArgument.Literal("PXAT"),
RespCommandArgument.Value(milliseconds.toString)
)
case (key, GetExpire.UnixTimeSeconds(seconds)) =>
case (key, GetExpire.GetExpireUnixTimeSeconds(seconds)) =>
RespCommand(
RespCommandArgument.Key(key),
RespCommandArgument.Literal("EXAT"),
Expand Down Expand Up @@ -419,15 +419,15 @@ object Input {
case object SetExpireInput extends Input[SetExpire] {
def encode(data: SetExpire): RespCommand =
data match {
case SetExpire.KeepTtl =>
case SetExpire.KeepTtl =>
RespCommand(RespCommandArgument.Literal("KEEPTTL"))
case SetExpire.Milliseconds(milliseconds) =>
case SetExpire.SetExpireMilliseconds(milliseconds) =>
RespCommand(RespCommandArgument.Literal("PX"), RespCommandArgument.Value(milliseconds.toString))
case SetExpire.Seconds(seconds) =>
case SetExpire.SetExpireSeconds(seconds) =>
RespCommand(RespCommandArgument.Literal("EX"), RespCommandArgument.Value(seconds.toString))
case SetExpire.UnixTimeMilliseconds(milliseconds) =>
case SetExpire.SetExpireUnixTimeMilliseconds(milliseconds) =>
RespCommand(RespCommandArgument.Literal("PXAT"), RespCommandArgument.Value(milliseconds.toString))
case SetExpire.UnixTimeSeconds(seconds) =>
case SetExpire.SetExpireUnixTimeSeconds(seconds) =>
RespCommand(RespCommandArgument.Literal("EXAT"), RespCommandArgument.Value(seconds.toString))
}
}
Expand Down
20 changes: 10 additions & 10 deletions modules/redis/src/main/scala/zio/redis/options/Strings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ trait Strings {
sealed trait SetExpire

object SetExpire {
case object KeepTtl extends SetExpire
final case class Milliseconds(milliseconds: Long) extends SetExpire
final case class Seconds(seconds: Long) extends SetExpire
final case class UnixTimeMilliseconds(milliseconds: Long) extends SetExpire
final case class UnixTimeSeconds(seconds: Instant) extends SetExpire
case object KeepTtl extends SetExpire
final case class SetExpireMilliseconds(milliseconds: Long) extends SetExpire
final case class SetExpireSeconds(seconds: Long) extends SetExpire
final case class SetExpireUnixTimeMilliseconds(milliseconds: Long) extends SetExpire
final case class SetExpireUnixTimeSeconds(seconds: Instant) extends SetExpire
}

sealed trait GetExpire

object GetExpire {
final case class Milliseconds(milliseconds: Long) extends GetExpire
case object Persist extends GetExpire
final case class Seconds(seconds: Long) extends GetExpire
final case class UnixTimeMilliseconds(milliseconds: Long) extends GetExpire
final case class UnixTimeSeconds(seconds: Long) extends GetExpire
final case class GetExpireMilliseconds(milliseconds: Long) extends GetExpire
final case class GetExpireSeconds(seconds: Long) extends GetExpire
final case class GetExpireUnixTimeMilliseconds(milliseconds: Long) extends GetExpire
final case class GetExpireUnixTimeSeconds(seconds: Long) extends GetExpire
case object Persist extends GetExpire
}

case object GetKeyword {
Expand Down
14 changes: 10 additions & 4 deletions modules/redis/src/test/scala/zio/redis/InputSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1300,20 +1300,26 @@ object InputSpec extends BaseSpec {
test("GetExInput - valid value") {
for {
resultSeconds <-
ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.Seconds(1))))
ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.GetExpireSeconds(1))))
resultMilliseconds <-
ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.Milliseconds(100))))
ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.GetExpireMilliseconds(100))))
resultUnixTimeSeconds <-
ZIO.attempt(
GetExInput[String]().encode(
scala.Tuple2("key", GetExpire.UnixTimeSeconds(Instant.parse("2021-04-06T00:00:00Z").getEpochSecond))
scala.Tuple2(
"key",
GetExpire.GetExpireUnixTimeSeconds(Instant.parse("2021-04-06T00:00:00Z").getEpochSecond)
)
)
)
resultUnixTimeMilliseconds <-
ZIO.attempt(
GetExInput[String]().encode(
scala
.Tuple2("key", GetExpire.UnixTimeMilliseconds(Instant.parse("2021-04-06T00:00:00Z").toEpochMilli))
.Tuple2(
"key",
GetExpire.GetExpireUnixTimeMilliseconds(Instant.parse("2021-04-06T00:00:00Z").toEpochMilli)
)
)
)
resultPersist <- ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.Persist)))
Expand Down

0 comments on commit 7fdda22

Please sign in to comment.