-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: master
Are you sure you want to change the base?
Conversation
4892dc4
to
b31ae8a
Compare
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 |
There was a problem hiding this comment.
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
andInstant
withLong
and ensure they're valid
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 |
There was a problem hiding this comment.
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"))) |
There was a problem hiding this comment.
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")))) && |
There was a problem hiding this comment.
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(..., ..., ...)
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 |
There was a problem hiding this comment.
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
Summary:
Update
(XX
,NX
,LT
,GT
) toUpdate
(XX
,NX
) andUpdateByScore
(LT
,GT
)SET
command only takesNX | XX
(more info here)ZADD
command takes bothNX | XX
andLT | GT
(more info here)Note: The GT, LT and NX options are mutually exclusive. (This has not been implemented)
setEx
,setNx
, andpSetEx
commands because they were deprecated since version2.6.12
KeepTtl
and durations becauseSET
command can't take bothexpireAt
andkeepTtl
getEx
commands into one