Skip to content

Conversation

@AmirAllayarovSofteq
Copy link
Contributor

No description provided.

@AmirAllayarovSofteq AmirAllayarovSofteq added the feature New feature or request label Jan 12, 2023
@AmirAllayarovSofteq AmirAllayarovSofteq self-assigned this Jan 12, 2023
): Promise<Recommendation> {
try {
const dangerousCommands = await redisClient.sendCommand(
new Command('command', ['LIST', 'FILTERBY', 'aclcat', 'dangerous'], { replyEncoding: 'utf8' }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will not work for Redis < 7

});

const activeDangerousCommands = await Promise.all(
filteredDangerousCommands.map(async (command) => await this.checkCommandInfo(redisClient, command)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the goal to additionally send command info <cmd> here?
Is it possible to use command without any args and filter all commands from that list?

return false;
}

private async checkCommandInfo(redisClient: Redis | Cluster, command: string): Promise<string> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this method is not needed


return isJSONOrHash ? { name: RECOMMENDATION_NAMES.SEARCH_INDEXES } : null;
}
const sortedSets = keys
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check types for standalone should be in separate method to decrease complexity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I'm fine with how you are processing search recommendations for standalone. nice!

client: any,
): Promise<Recommendation> {
try {
if (client.isCluster) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move this to separate method. Let's have 2 separate method determineForCluster*... and determineForStandalone*...

let processedKeysNumber = 0;
let isJSONOrHash = false;
let sortedSetNumber = 0;
while (
Copy link
Collaborator

Choose a reason for hiding this comment

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

while? why?
I think we should use here Promise.all to not wait before processing the next key.
In general I think that this implementation should be the same as for Standalone databases but with Promise.all -> sendCommand instead of piepeline

new Command('type', [sortedSetMember[0]], { replyEncoding: 'utf8' }),
) as string;
} catch (err) {
if (err && checkRedirectionError(err)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure that we need this?
As I remember we can simplify this "redirection" functionality a lot.
Let's use not node client but parent client (general cluster client) to execute commands. In this case all commands will be routed to needed node automatically, no? did you check this behaviour?

processedKeysNumber += 1;
sortedSetNumber += 1;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I would like to see 2 separate methods for cluster and standalone but with almost the same logic except pipeline vs Promise.all sendCommand (on cluster client). Is it possible?

recommendationToExclude.push(...foundedRecommendationNames);
jobsArray.push(foundedRecommendations);
return flatten(jobsArray);
}, Promise.resolve([]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I understand this idea. It is not readable a little bit but should work. I would prefer to have Map with recommendations when each recommendation has own type and based on it we will check this recommendation or not. But let's revise this approach and refactor current solution when we will add batch or scan more functionality

@nmammadli nmammadli merged commit 84570dc into feature/RI-3527_lua_scripts Jan 24, 2023
@nmammadli nmammadli deleted the feature/RI-3971-3572_add_recommendations branch January 24, 2023 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants