-
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
Support SORT command in Keys API #302
Conversation
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.
@sloanesturz thank you for taking care of this! I left some general remarks, but more specifically, I don't think we should expose two separate commands. I would propose to:
- apply the proposed fixes
- represent missing terms (e.g. alpha)
- unify commands into single sort
Please take a look at geo API, as there's quite a few options defined there, and it might serve as an "inspiration" here :).
final def sort( | ||
key: String, | ||
by: Option[String] = None, | ||
limitOffset: Option[(Int, Int)] = None, |
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 have this defined among sorted sets (see here). I propose that you reuse it and move the option itself to shared options.
key: String, | ||
by: Option[String] = None, | ||
limitOffset: Option[(Int, Int)] = None, | ||
desc: Boolean = false, |
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.
Order is defined as geo options here. Please do the same approach:
- move to shared
- use it instead of plain boolean
OK, thanks for the pointers to those options fields -- definitely more clean to use those instead of my approach. The pattern in the Geo package has a lot of overlap and is clearly the right way to go.
What should the return type of this method be? If we |
One option might be to define a custom response type (ADT of possible responses), but let's play around with this, perhaps something better pops up. |
OK, let me take a crack at your first suggestions before taking on the second one. In my experience, returning an
|
def sortArguments( | ||
by: Option[String], | ||
limitOffset: Option[(Int, Int)], | ||
desc: Boolean, | ||
get: List[String], | ||
alpha: Boolean | ||
): List[String] = | ||
by.map(sortBy => List("BY", sortBy)).getOrElse(List.empty) ++ | ||
limitOffset.map { case (count, offset) => List("LIMIT", offset.toString, count.toString) } | ||
.getOrElse(List.empty) ++ | ||
get.flatMap(getAt => List("GET", getAt)) ++ | ||
List(if (desc) "DESC" else "ASC") ++ | ||
(if (alpha) List("ALPHA") else List.empty) | ||
|
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.
Should this be deleted?
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.
Fixed!
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.
Almost there! Since we opted for this approach of command per output (with a good reason, as you elaborated), do you mind doing a quick scan of the similar commands and filing them in an issue so that we can align the API? 🙏
@@ -126,6 +138,11 @@ object Input { | |||
Chunk(encodeString("LIMIT"), encodeString(data.offset.toString), encodeString(data.count.toString)) | |||
} | |||
|
|||
final case class ListInput[-A](input: Input[A]) extends Input[List[A]] { | |||
override private[redis] def encode(data: List[A]): Chunk[RespValue.BulkString] = |
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.
override private[redis] def encode(data: List[A]): Chunk[RespValue.BulkString] = | |
def encode(data: List[A]): Chunk[RespValue.BulkString] = |
However, see the comment below, this might be unnecessary.
StringInput, | ||
OptionalInput(ByInput), | ||
OptionalInput(LimitInput), | ||
ListInput(GetInput), |
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.
This can actually be changed to OptionalInput(NonEmptyList[GetInput])
.
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.
clever!
Filed #306 for the GEO functions. |
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.
Nice work! 🚀
Fixes #218.
SORT has two different response types:
This is not easily expressible in Scala, so I created two separate functions, one for
SORT ... STORE ...
and one forSORT ...
This is my first commit to zio-redis, please let me know if I am not following any important functional or stylistic guidelines!