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

Improve 'SET' command #803

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

drmarjanovic
Copy link
Collaborator

@drmarjanovic drmarjanovic commented Apr 5, 2023

Summary:

  • Separate Update (XX, NX, LT, GT) to Update (XX, NX) and UpdateByScore (LT, GT)
    • SET command only takes NX | XX (more info here)
    • ZADD command takes both NX | XX and LT | GT (more info here)
      Note: The GT, LT and NX options are mutually exclusive. (This has not been implemented)
  • Removed setEx,setNx, and pSetEx commands because they were deprecated since version 2.6.12
  • Merge KeepTtl and durations because SET command can't take both expireAt and keepTtl
  • Merge getEx commands into one
  • Adapted tests

@drmarjanovic drmarjanovic marked this pull request as ready for review April 9, 2023 21:51
@drmarjanovic drmarjanovic requested a review from a team as a code owner April 9, 2023 21:51
@drmarjanovic drmarjanovic marked this pull request as draft April 9, 2023 21:51
@drmarjanovic drmarjanovic force-pushed the task-enrich-set-command branch from 4892dc4 to b31ae8a Compare September 15, 2024 19:51
@drmarjanovic drmarjanovic marked this pull request as ready for review September 16, 2024 16:56
@drmarjanovic drmarjanovic requested a review from mijicd September 16, 2024 16:57
@drmarjanovic drmarjanovic self-assigned this Sep 23, 2024
Comment on lines 104 to 107
case class SetExpireMilliseconds(duration: Duration) extends SetExpire
case class SetExpireSeconds(duration: Duration) extends SetExpire
case class SetExpireUnixTimeMilliseconds(instant: Instant) extends SetExpire
case class SetExpireUnixTimeSeconds(instant: Instant) extends SetExpire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  • keep case classes final
  • since units are dictated by redis, I would replace Duration and Instant with Long and ensure they're valid

Comment on lines 113 to 116
case class GetExpireMilliseconds(duration: Duration) extends GetExpire
case class GetExpireSeconds(duration: Duration) extends GetExpire
case class GetExpireUnixTimeMilliseconds(instant: Instant) extends GetExpire
case class GetExpireUnixTimeSeconds(instant: Instant) extends GetExpire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

GetExAtInput[String]().encode(
scala.Tuple3("key", ExpiredAt.SetExpireAtSeconds, Instant.parse("2021-04-06T00:00:00Z"))
GetExInput[String]().encode(
scala.Tuple2("key", GetExpire.GetExpireUnixTimeSeconds(Instant.parse("2021-04-06T00:00:00Z")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can be less verbose here :)

} yield assert(result)(equalTo(RespCommand(Key("key"), Literal("PERSIST")))) &&
assert(resultWithoutOption)(equalTo(RespCommand(Key("key"))))
resultPersist <- ZIO.attempt(GetExInput[String]().encode(scala.Tuple2("key", GetExpire.Persist)))
} yield assert(resultSeconds)(equalTo(RespCommand(Key("key"), Literal("EX"), Value("1")))) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should start replacing assert(...)(...) && assert(...)(...) with assertTrue(..., ..., ...)

Comment on lines 102 to 105
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to prevent negative inputs. Also, you missed one Instant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants