-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Redis 6.2] Add MINID and LIMIT options to xtrim #1170
Conversation
lib/redis/commands/streams.rb
Outdated
strategy = strategy.to_s.upcase | ||
unless %w[MAXLEN MINID].include?(strategy) | ||
raise ArgumentError, "strategy must be MINID or MAXLEN" | ||
end |
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'm not convinced all this validation is worth it, might as well directly pass it to the server.
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.
Updated in 5d7ceea
lib/redis/commands/streams.rb
Outdated
raise ArgumentError, "strategy must be MINID or MAXLEN" | ||
end | ||
|
||
args = [:xtrim, key, strategy, (approximate ? '~' : nil), len_or_id].compact |
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.
args = [:xtrim, key, strategy, (approximate ? '~' : nil), len_or_id].compact | |
args = [:xtrim, key, strategy] | |
args << '~' if approximate | |
args << len_or_id |
I know the code was like this, but I'd rather add to the array only when necessary than to compact nil elements. It's less error prone.
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.
Apparently, we are going to have to either compact/handle the nils in this test case or change the behavior:
https://github.com/redis/redis-rb/blob/master/test/lint/streams.rb#L131 . If we don't then, the we receive a TypeError with this message Unsupported command argument type: NilClass
.
A couple of options:
- Change the behavior so that we throw the TypeError instead of a Redis::CommandError
- Leave as-is, and compact one
- Combine your suggestion above with a compact before we call
send_command
What's your preference?
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.
or change the behavior:
https://github.com/redis/redis-rb/blob/master/test/lint/streams.rb#L131
Yeah, that is inconsistent with the rest of the library, just remove that part of the test.
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.
Updated and squashed into 5d7ceea
ffc4d3d
to
5d7ceea
Compare
lib/redis/commands/streams.rb
Outdated
args << '~' if approximate | ||
args << len_or_id | ||
args.concat(['LIMIT', limit]) if limit | ||
send_command(args.compact) |
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.
send_command(args.compact) | |
send_command(args) |
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.
Sorry, that slipped through. Updated in 4321159
5d7ceea
to
4321159
Compare
The CI failures seem legit. I assume there another test passing nil as argument somewhere. |
So the CI failures were because I expected that the ensure would be skipped in cases where were were skipping the spec. Seems like that's common enough to have it's own Rubocop cop. I pushed up d7926fe. If that looks good, I'll squash the changes. |
d7926fe
to
e76e1cb
Compare
Alright, I squashed the commits. Thanks for working with me on this. |
Adds the following options to the xtrim command:
This probably isn't the ideal interface for the
#xtrim
method, but I tried not to add breaking changes.See the documentation at https://redis.io/commands/xtrim/
References #978