Skip to content

Return empty modules array when module command is not available #42

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Redis/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ public static function registerCommandsRediska(): void

public static function getRediSearchVersion(Client $client): ?string
{
$modules = $client->executeRaw('module', 'list') ?? [];
try {
$modules = $client->executeRaw('module', 'list') ?? [];
} catch (\Throwable $exception) {
Copy link
Owner

Choose a reason for hiding this comment

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

if (strpos($exception->getMessage(), 'unknown command') === false) {
Copy link
Owner

Choose a reason for hiding this comment

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

Yoda style test is used (see PHP-CS-Fixer error: https://github.com/MacFJA/php-redisearch/runs/7054519075?check_suite_focus=true)

Suggested change
if (strpos($exception->getMessage(), 'unknown command') === false) {
if (false === strpos($exception->getMessage(), 'unknown command')) {

throw $exception;
}
$modules = [];
Copy link
Owner

Choose a reason for hiding this comment

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

It can return null directly, because the foreach will have nothing to run

Suggested change
$modules = [];
return null;

}

foreach ($modules as $module) {
$data = array_column(
Expand Down