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

Sorted set new commands: ZDIFF, ZDIFFSTORE, ZINTER, ZINTERCARD, and ZUNION #2075

Merged
merged 14 commits into from
Apr 12, 2022

Conversation

Avital-Fine
Copy link
Contributor

Covers:

ZDIFF
ZDIFFSTORE
ZINTER
ZINTERCARD
ZUNION

#2055

Copy link
Collaborator

@NickCraver NickCraver left a comment

Choose a reason for hiding this comment

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

Great work here! Added some comments inline - as always happy to adjust and push or just keep commenting, whichever is a bigger time/sync save on your end. A few questions inline for thoughts!

tests/StackExchange.Redis.Tests/SortedSets.cs Outdated Show resolved Hide resolved
tests/StackExchange.Redis.Tests/SortedSets.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
@NickCraver NickCraver changed the title Sorted set new commands Sorted set new commands: ZDIFF, ZDIFFSTORE, ZINTER, ZINTERCARD, and ZUNION Apr 10, 2022
@NickCraver
Copy link
Collaborator

@slorello89 I've touched this a lot, so would appreciate a third set of eyes if you get a chance!

Copy link
Collaborator

@slorello89 slorello89 left a comment

Choose a reason for hiding this comment

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

@NickCraver just have some questions about the efficiency vs maintainability bits of the Message Creation.


private Message GetSortedSetCombineCommandMessage(SetOperation operation, RedisKey[] keys, double[]? weights, Aggregate aggregate, bool withScores, CommandFlags flags)
{
var command = operation switch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably want to move this logic to the SetOperation enum as an extension method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 This makes sense with an arg - done!

src/StackExchange.Redis/RedisDatabase.cs Outdated Show resolved Hide resolved
}

var i = 0;
var values = new RedisValue[1 + keys.Length +
Copy link
Collaborator

Choose a reason for hiding this comment

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

How much more expensive would it be to initialize a List with this capacity and using Add/AddRange as opposed to an array and then having to track i, this is a bit. . . feels like we're reinventing the wheel here? List<T>(int) is effectively just doing the same initialization, since it's initialized with the correct capacity it shouldn't over allocate nor have to dynamically reallocate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's allocate more than double. At the very lease we're resizing without sizes, but also: look inside Message to see a .ToArray() which is going to copy as well. I agree it's not awesome to do things manually, but 2x+ allocations aren't awesome either :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh I gotcha. TIL

if (keys == null) throw new ArgumentNullException(nameof(keys));

var i = 0;
var values = new RedisValue[1 + keys.Length + (limit > 0 ? 2 : 0)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above.

@NickCraver
Copy link
Collaborator

@slorello89 made some tweaks (good suggestions!) - done!

Copy link
Collaborator

@slorello89 slorello89 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@NickCraver NickCraver merged commit e18b2c1 into StackExchange:main Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants