mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.24k stars 214 forks source link

Model Caching gives Class 'Redis' not found when Laravel Scout is importing #367

Closed binotm25 closed 3 years ago

binotm25 commented 3 years ago

Describe the bug Model caching works fine with phpredis as the client. But when I use Laravel scout to import data to its index it gives Redis not found error. When I disabled the Cachable trait the import works fine.

php artisan scout:import "App\Models"

Stack Trace Class 'Redis' not found at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:74

Environment

mikebronner commented 3 years ago

@binotm25 Please provide the full stack trace from the log file.

binotm25 commented 3 years ago

Thanks for the fast update, here is the complete stack trace:

Class 'Redis' not found {"exception":"[object] (Error(code: 0): Class 'Redis' not found at /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:75)
[stacktrace]
#0 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(28): Illuminate\\Redis\\Connectors\\PhpRedisConnector->createClient()
#1 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(32): Illuminate\\Redis\\Connectors\\PhpRedisConnector->Illuminate\\Redis\\Connectors\\{closure}()
#2 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(110): Illuminate\\Redis\\Connectors\\PhpRedisConnector->connect()
#3 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(90): Illuminate\\Redis\\RedisManager->resolve()
#4 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(242): Illuminate\\Redis\\RedisManager->connection()
#5 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(54): Illuminate\\Cache\\RedisStore->connection()
#6 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/TagSet.php(87): Illuminate\\Cache\\RedisStore->get()
#7 [internal function]: Illuminate\\Cache\\TagSet->tagId()
#8 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/TagSet.php(76): array_map()
#9 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/TagSet.php(66): Illuminate\\Cache\\TagSet->tagIds()
#10 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/TaggedCache.php(102): Illuminate\\Cache\\TagSet->getNamespace()
#11 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/TaggedCache.php(91): Illuminate\\Cache\\TaggedCache->taggedItemKey()
#12 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(97): Illuminate\\Cache\\TaggedCache->itemKey()
#13 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(409): Illuminate\\Cache\\Repository->get()
#14 /home/web/public_html/Test/vendor/genealabs/laravel-model-caching/src/Traits/Buildable.php(296): Illuminate\\Cache\\Repository->rememberForever()
#15 /home/web/public_html/Test/vendor/genealabs/laravel-model-caching/src/Traits/Buildable.php(231): GeneaLabs\\LaravelModelCaching\\CachedBuilder->retrieveCachedValue()
#16 /home/web/public_html/Test/vendor/genealabs/laravel-model-caching/src/Traits/Buildable.php(97): GeneaLabs\\LaravelModelCaching\\CachedBuilder->cachedValue()
#17 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(92): GeneaLabs\\LaravelModelCaching\\CachedBuilder->get()
#18 /home/web/public_html/Test/vendor/laravel/scout/src/SearchableScope.php(39): Illuminate\\Database\\Eloquent\\Builder->chunkById()
#19 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1387): Laravel\\Scout\\SearchableScope->Laravel\\Scout\\{closure}()
#20 /home/web/public_html/Test/vendor/genealabs/laravel-model-caching/src/Traits/Caching.php(22): Illuminate\\Database\\Eloquent\\Builder->__call()
#21 /home/web/public_html/Test/vendor/laravel/scout/src/Searchable.php(130): GeneaLabs\\LaravelModelCaching\\CachedBuilder->__call()
#22 /home/web/public_html/Test/vendor/laravel/scout/src/Console/ImportCommand.php(45): App\\Models\\Store::makeAllSearchable()
#23 [internal function]: Laravel\\Scout\\Console\\ImportCommand->handle()
#24 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): call_user_func_array()
#25 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#26 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure()
#27 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(39): Illuminate\\Container\\BoundMethod::callBoundMethod()
#28 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call()
#29 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\\Container\\Container->call()
#30 /home/web/public_html/Test/vendor/symfony/console/Command/Command.php(258): Illuminate\\Console\\Command->execute()
#31 /home/web/public_html/Test/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#32 /home/web/public_html/Test/vendor/symfony/console/Application.php(911): Illuminate\\Console\\Command->run()
#33 /home/web/public_html/Test/vendor/symfony/console/Application.php(264): Symfony\\Component\\Console\\Application->doRunCommand()
#34 /home/web/public_html/Test/vendor/symfony/console/Application.php(140): Symfony\\Component\\Console\\Application->doRun()
#35 /home/tps/public_html/Test/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run()
#36 /home/tps/public_html/Test/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#37 /home/tps/public_html/Test/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#38 {main}
"} 
mikebronner commented 3 years ago

This does not appear to be an error with this package. Please be sure to install the appropriate Redis client according to Laravel's documentation: https://laravel.com/docs/6.x/redis#phpredis. Have you done that already?

binotm25 commented 3 years ago

Yes, I already have done that. It works perfectly fine with this package, I can see the cache model records in the Redis also. It only crashes when I do the scout import, or save when the scout searchable trait is used on the model.

$app = RedisManager::connection();
$app->set('key', 'Testing PhpRedis');
echo $app->get('key');

This also works. I will also open a new issue on scout as well.

mikebronner commented 3 years ago

@binotm25 Thanks for following up! Would you be able to set up a test repo with code that fails and short instructions on how to trigger the failing code? That would help tremendously. Thanks! I have never gotten this error when using Scout in combination with this package.

binotm25 commented 3 years ago

Oops my bad. Turns out the phpredis was not working from cli although it was working fine with the nginx and php-fpm. Upon close inspection the redis.ini wasn't imported into the php cli folder. After importing it, it is working perfectly.

Thank you so much for this package. Sorry I couldn't figured it out earlier.

mikebronner commented 3 years ago

Awesome that you got it working! :)