我该如何解决“Predis\ClientException:命令'EXiSTS' 不是已注册的 Redis 命令。”错误?
How can i solve " Predis\ClientException : Command 'EXiSTS' is not a registered Redis command. " error?
我在自定义提供程序中使用了 Redis class,但在服务器上不起作用。
本地没有任何问题,但我不明白为什么它在服务器上不起作用。
当我使用 artisan 命令时出现此错误。
" Predis\ClientException : 命令 'EXiSTS' 不是已注册的 Redis 命令。
在 /var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Profile/RedisProfile.php:88
84| {
85| $commandID = strtoupper($commandID);
86|
87|如果 (!isset($this->commands[$commandID])) {
88| throw new ClientException("Command '$commandID' is not a registered Redis command.");
89| }
90|
91| $commandClass = $this->commands[$commandID];
92| $command = new $commandClass();
异常跟踪:
1 Predis\Profile\RedisProfile::createCommand("EXiSTS")
/var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Client.php:323
2 Predis\Client::createCommand("exists")
/var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Client.php:314
请使用参数-v 以查看更多详细信息。
“
我的代码:
public function boot()
{
$redis = new Redis();
if ( !$redis->exists('activity_of_week') ) {
$redis->set('activity_of_week',serialize( Activity::ofWeek(10) ));
}
if ( !$redis->exists('popular_companies') ) {
$redis->set('popular_companies',serialize( TopRateCompanies::sortBy()->take(10) ));
}
$activityOfWeeks = $redis->get('activity_of_week');
$popularCompanies = $redis->get('popular_companies');
$popular = new PopularCategory();
$popularCategories = $popular->take(10);
View::composer('frontend.layout.footer', function ($view) use ($activityOfWeeks, $popularCompanies, $popularCategories) {
/**
* @var ViewAlias $view
*/
$keys = [ 'email' => 'contact-email',
'facebook' => 'facebook',
'instagram' => 'instagram',
'twitter' => 'twitter',
'youtube' => 'youtube',
'phone' => 'contact-phone',
];
$info = array_map( [$this,'contactInfo'],$keys );
$view->with('contact', $info)
->with('activityOfWeeks', $activityOfWeeks)
->with('popularCompanies', $popularCompanies)
->with('popularCategories', $popularCategories);
});
}
public function contactInfo($key)
{
return Settings::where('key',$key)->firstOrFail()->value;
}
请帮帮我。
这是一个语言环境问题。我相信您在您的应用程序中使用了土耳其语言环境。这会导致 strtoupper
函数出现问题。
有一个类似的问题你可以看看这里:https://github.com/nrk/predis/issues/372
作为解决方案,如果您的情况可以接受,您可以尝试更改本地。或者按照问题中的建议,您可以使用 Laravel 提供的 Redis facade。 Redis::EXISTS
像这样。
我在自定义提供程序中使用了 Redis class,但在服务器上不起作用。
本地没有任何问题,但我不明白为什么它在服务器上不起作用。
当我使用 artisan 命令时出现此错误。
" Predis\ClientException : 命令 'EXiSTS' 不是已注册的 Redis 命令。
在 /var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Profile/RedisProfile.php:88 84| { 85| $commandID = strtoupper($commandID); 86| 87|如果 (!isset($this->commands[$commandID])) {
88| throw new ClientException("Command '$commandID' is not a registered Redis command."); 89| } 90| 91| $commandClass = $this->commands[$commandID]; 92| $command = new $commandClass();
异常跟踪:
1 Predis\Profile\RedisProfile::createCommand("EXiSTS") /var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Client.php:323
2 Predis\Client::createCommand("exists") /var/www/vhosts/website.com/laravel_folder/website/vendor/predis/predis/src/Client.php:314
请使用参数-v 以查看更多详细信息。 “
我的代码:
public function boot()
{
$redis = new Redis();
if ( !$redis->exists('activity_of_week') ) {
$redis->set('activity_of_week',serialize( Activity::ofWeek(10) ));
}
if ( !$redis->exists('popular_companies') ) {
$redis->set('popular_companies',serialize( TopRateCompanies::sortBy()->take(10) ));
}
$activityOfWeeks = $redis->get('activity_of_week');
$popularCompanies = $redis->get('popular_companies');
$popular = new PopularCategory();
$popularCategories = $popular->take(10);
View::composer('frontend.layout.footer', function ($view) use ($activityOfWeeks, $popularCompanies, $popularCategories) {
/**
* @var ViewAlias $view
*/
$keys = [ 'email' => 'contact-email',
'facebook' => 'facebook',
'instagram' => 'instagram',
'twitter' => 'twitter',
'youtube' => 'youtube',
'phone' => 'contact-phone',
];
$info = array_map( [$this,'contactInfo'],$keys );
$view->with('contact', $info)
->with('activityOfWeeks', $activityOfWeeks)
->with('popularCompanies', $popularCompanies)
->with('popularCategories', $popularCategories);
});
}
public function contactInfo($key)
{
return Settings::where('key',$key)->firstOrFail()->value;
}
请帮帮我。
这是一个语言环境问题。我相信您在您的应用程序中使用了土耳其语言环境。这会导致 strtoupper
函数出现问题。
有一个类似的问题你可以看看这里:https://github.com/nrk/predis/issues/372
作为解决方案,如果您的情况可以接受,您可以尝试更改本地。或者按照问题中的建议,您可以使用 Laravel 提供的 Redis facade。 Redis::EXISTS
像这样。