-
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
#342: Implement hrandfield command and support it in TestExecutor #370
Conversation
} | ||
|
||
/** | ||
* Return an array of distinct fields. The array's length is either `count` or the hash's number of fields if `count` is greater. |
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.
Please keep the document consistent with other commands.Such as initials, full stop.
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.
@jxnu-liguobin Sorry for that. I have tried to solve this issues, let me know if it's correct now.
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.
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.
Definitely the second one. However, if there are no proboems with the implementation, let's merge this and do the docs unification in the follow up.
for { | ||
kvs <- keysAndValues | ||
fields <- selectValues(count.get, kvs.toVector) | ||
fieldsAndValues = fields.map { case (k, v) => Seq(k, v) }.flatten |
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.
Instead of flatten
it should be possible to directly use flatMap
} else if (count.isDefined) { | ||
for { | ||
kvs <- keysAndValues | ||
keys = kvs.map(_._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.
For better readability, I prefer kvs.map {case (k, _) => k}
but up to you just a suggestion.
@@ -972,6 +972,49 @@ private[redis] final class TestExecutor private ( | |||
} yield RespValue.Array(Chunk.fromIterable(values)) | |||
) | |||
|
|||
case api.Hashes.HRandField => | |||
val key = input(0).asString | |||
val count = if (input.size == 1) None else input(1).asString.toLongOption |
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 .toLongOption
is not available in scala 2.12
LGTM |
Closes #342
Implements HRANDFIELD as two different methods.
As mentioned in the redis documentation, HRANGEFIELD can return a field or an array of fields/values, depending on the value of the count parameter.
This implementation has two different methods, differentiated by their return value.
If count is negative, it allows to return repeated field/values.