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

Enhance code readability #241

Merged
merged 66 commits into from
Mar 19, 2024
Merged

Enhance code readability #241

merged 66 commits into from
Mar 19, 2024

Conversation

nimanikoo
Copy link
Contributor

Hello, I hope you are well
Thank you for helping open source and building this project for the .NET community
Out of curiosity, I was reviewing the codes of this repository and I found some points that might be good to correct.
One of the performance improvements was where you used lists
The next thing is that you can use the primary constructor according to the latest version of .NET
In some cases, we could have written the code in a more concise and readable manner and used expressions
There were several typo problems that I corrected
I hope these things are helpful and I will be happy to contribute to the progress of this project
Please check and let me know the result

gerzse and others added 19 commits January 25, 2024 11:41
Fix some typos in the markdown files and run `dotnet format` on existing
code.
Change the settings so that documentation is included in the build.
Add support for the BZMPOP command.

This command is blocking on the server, so it goes against the current
policy of the StackExchange.Redis library. Therefore make it obvious in
the code documentation that attention must be given to the timeout in
the connection multiplexer.

The StackExchange.Redis library already defines a type for the payload
returned by BZMPOP (which is the same as for ZMPOP), namely the
SortedSetPopResult class. However, the constructor of that class is
internal in the library, so we can't create instances of it. Therefore
roll our out type for a <value, score> pair, and use Tuple to pair a key
with a list of such <value, score> pairs.
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2024

Codecov Report

Attention: Patch coverage is 93.76900% with 41 lines in your changes are missing coverage. Please review.

Project coverage is 94.35%. Comparing base (ccd74b5) to head (4159b23).

Files Patch % Lines
src/NRedisStack/Bloom/BloomCommandBuilder.cs 77.27% 5 Missing and 5 partials ⚠️
src/NRedisStack/Search/AggregationResult.cs 73.33% 6 Missing and 2 partials ⚠️
...rc/NRedisStack/CountMinSketch/CmsCommandBuilder.cs 84.21% 3 Missing and 3 partials ⚠️
src/NRedisStack/Search/DataTypes/InfoResult.cs 90.47% 1 Missing and 5 partials ⚠️
src/NRedisStack/Search/Document.cs 87.50% 3 Missing and 2 partials ⚠️
src/NRedisStack/CoreCommands/CoreCommands.cs 97.29% 1 Missing and 1 partial ⚠️
src/NRedisStack/Json/JsonCommandBuilder.cs 90.90% 0 Missing and 2 partials ⚠️
src/NRedisStack/Json/DataTypes/KeyValuePath.cs 75.00% 0 Missing and 1 partial ⚠️
src/NRedisStack/Search/AggregationRequest.cs 99.11% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #241      +/-   ##
==========================================
- Coverage   94.37%   94.35%   -0.02%     
==========================================
  Files          88       88              
  Lines        5461     5425      -36     
  Branches      506      498       -8     
==========================================
- Hits         5154     5119      -35     
+ Misses        181      180       -1     
  Partials      126      126              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@shacharPash shacharPash left a comment

Choose a reason for hiding this comment

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

Thank you!
A lot of good changes! 👍 👍
I have a question, some of the changes you made are also relevant to the other modules (topK, search, cuckooFilter, etc.), is there a reason why you didn't make changes there?

@@ -157,7 +157,7 @@ public interface IJsonCommandsAsync
/// <param name="value">The value to increment by.</param>
/// <returns>The new values after being incremented, or null if the path resolved a non-numeric.</returns>
/// <remarks><seealso href="https://redis.io/commands/json.numincrby"/></remarks>
Task<double?[]> NumIncrbyAsync(RedisKey key, string path, double value);
Task<double?[]> NumIncrByAsync(RedisKey key, string path, double value);
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Its breaking change
  2. The sync command still called NumIncrby

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback you gave me and the time you took to review
This is valuable for me
Actually, when I applied these changes, it was after work and I was very tired
I was reviewing the codes of this project out of curiosity and made some changes
To be honest, I am very interested in participating and contributing to this project
I will fix the problems you mentioned and I would be grateful if you check and give me feedback again
I can fix all the parts you mentioned
We can also communicate via email or wherever you prefer

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Nima, I pushed a small commit reverting these ToString() calls. It was easiest, given that it's a super small change. Thanks for your patience!

gerzse and others added 9 commits January 29, 2024 12:22
Improve the signatures of the new methods, to transparently replicate
the structure of the Redis command, i.e. timeout is mandatory and the
first argument, order is mandatory.

Add a version of the method that works for a single argument, in the
spirit of the StackExchange.Redis library.
Add a dedicated enum for the MIN and MAX arguments. It feels cleaner
than using Order and having to mentally map Ascending to Min and
Descending to Max.
The primary constructor syntax seems to be not supported by older dotnet
versions, so don't use it. Also switch from `class` to `struct`, to
better reflect the fact that RedisValueWithScore is just a data storage
item.
It seems that workflows cancel each other out if they are in the same
concurrency group: https://github.com/orgs/community/discussions/41518

Try to separate four workflows that run on PRs into separate concurency
groups. Ideally this will avoid the cancelation.

They should still cancel runs from previous pushes, each in their own
group.
Collection literals are not supported by older dotnet versions, it
seems, so stop using them for now.
Some tests (for the Gears module) seem flaky, they fails sometime with
RedisTimeoutException. Try to double the timeout in the connection
multiplexer, from 5 to 10 seconds, hopefully this helps.
@nimanikoo nimanikoo requested a review from shacharPash March 3, 2024 11:41
@shacharPash
Copy link
Contributor

Hi @nimanikoo how are you?, regarding the missing modules - if you run the docker in the README (docker run -p 6379:6379 --name redis-stack redis/redis-stack:latest) you should get all the modules. I would appreciate it if you could specify what exactly you ran/downloaded so that we can understand why you were missing modules.

Secondly, the tests that run on .NET 6 and 7 still fail... because of a syntax that is only supported by .NET 8, for example: List<object> args = [key];

@nimanikoo, did you see my comment?

@nimanikoo
Copy link
Contributor Author

Hi dear @shacharPash , how are you? I read your comment and this conflict was on my local machine. Redis was running locally on my machine on port 6379 and it did not have a number of Redis stack modules and it was causing problems, I fixed this local conflict and the problem was solved.Currently, all the tests are passed correctly, except the tests related to the search, which @omidpakdel mentioned, and I have the same problem in branch Master for tests.

@shacharPash
Copy link
Contributor

Hey @nimanikoo, how are you?
What remains to be done is to delete the changes that have the syntax supported only in .NET 8 and not in the previous versions of .NET and then we can merge
can you do it?

@nimanikoo
Copy link
Contributor Author

Hi @shacharPash ,How are you doing?
I will definitely fix all the issues that you've identified and that are causing conflicts.
I would really appreciate it if you could please provide me with a detailed list of the specific issues that are causing the conflicts so that I can address them all thoroughly.

@shacharPash
Copy link
Contributor

@nimanikoo You can see the problematic sections in what failed the .NET 6 and 7 tests

…ror : error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version
@nimanikoo
Copy link
Contributor Author

Hello @shacharPash , How are you doing?
I've fixed all the compiler errors that were there, and I'm confident that we won't have any more issues with the .NET version or syntax.
I would have really loved to be able to fully utilize the new features of .NET 8 in this project, but unfortunately, it's not possible.
Please let me know if there's anything else I can do to help us get closer to merging.

Copy link
Contributor

@gerzse gerzse left a comment

Choose a reason for hiding this comment

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

Looks good to me. Two minor comments.

@@ -27,7 +27,7 @@ public void run()

// STEP_START set_get
var res1 = db.StringSet("bike:1", "Deimos");
Console.WriteLine(res1); // true
Console.WriteLine(res1.ToString()); // true
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't ToString() implied here? These code snippets end up on the reddis.io web documentation, they should be as easy to read as possible.

Copy link
Contributor Author

@nimanikoo nimanikoo Mar 18, 2024

Choose a reason for hiding this comment

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

Hello Gabriel,
How are you?
Thanks for the points you mentioned.
I checked with branch master and found that .ToString() wasn't implemented, but I don't think it would cause any issues since it just logs.
Your opinion is still a priority, and if you agree, we can make some changes.


public static async Task<RedisResult> ExecuteAsync(this IDatabaseAsync db, SerializedCommand command)
{
if (!_setInfo) return await db.ExecuteAsync(command.Command, command.Args);
Copy link
Contributor

Choose a reason for hiding this comment

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

In this class I find the original logic easier to read. Now the db.ExecuteAsync(...) call is duplicated, so if we need to change it, it needs change in two places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a very good point. I fixed it. Thank you

@nimanikoo nimanikoo requested a review from gerzse March 18, 2024 07:12
Trying to keep code snippets as short as possible, since they get
published on redis.io as documentation. Hence reverting the addition of
the `ToString()` calls in some places.
@shacharPash shacharPash merged commit fc40221 into redis:master Mar 19, 2024
18 checks passed
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.

5 participants