如果没有运行Redis,我的项目将无法启动。如果我尝试在Laravel中不运行redis打开页面,我会收到此消息:
"无法建立连接,因为目标机器主动拒绝它。[tcp://127.0.0.1:6379]"
我尝试了1)php artisan config: cache,2)php artisan Clear:cache,3)作曲家删除predis/predis 4)作曲家删除predis 5)删除redis实例6)通过命令行卸载redis
任何帮助将不胜感激!谢谢!
缓存. php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache connection that gets used while
| using this caching library. This connection is used when another is
| not explicitly specified when executing a given caching function.
|
| Supported: "apc", "array", "database", "file", "memcached", "redis"
|
*/
'default' => env('CACHE_DRIVER', 'file'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
*/
'stores' => [
'apc' => [
'driver' => 'apc',
],
'array' => [
'driver' => 'array',
],
'database' => [
'driver' => 'database',
'table' => 'cache',
'connection' => null,
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
'redis' => [
'driver' => 'file',
'connection' => 'default',
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/
'prefix' => env(
'CACHE_PREFIX',
str_slug(env('APP_NAME', 'laravel'), '_').'_cache'
),
];
. env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:duZtCSIh12vDNOdmYW2kmMr9ONILxsH55f46npt5/Kg=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forum
DB_USERNAME=
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=bc05914be7f1db
MAIL_PASSWORD=0c73506a138d3f
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
RECAPTCHA_SECRET=
如果您不想安装任何缓存服务,如Redis或Memcached,您可以使用Laravel上的文件
或数据库
驱动程序。
要更改缓存驱动程序,您必须将CACHE_DRIVER
变量您的. env
文件更改为文件
,或者修改config/cache.php
文件。
默认的cache. php配置文件如下所示:
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache connection that gets used while
| using this caching library. This connection is used when another is
| not explicitly specified when executing a given caching function.
|
| Supported: "apc", "array", "database", "file",
| "memcached", "redis", "dynamodb"
|
*/
'default' => env('CACHE_DRIVER', 'file'),
env()
函数从第一个参数定义的环境变量中获取数据,并回退到第二个参数定义的值。因此,如果您的. env文件定义了一个CACHE_DRIVER变量,它将忽略第二个参数值。
有关详细信息,请参阅https://laravel.com/docs/5.8/cache
我刚才也遇到了同样的问题。错误:
"无法建立连接,因为目标机器主动拒绝它。[tcp://127.0.0.1:6379]"
这意味着应用程序中仍有一些东西使用redis来提供服务。
// .env
CACHE_DRIVER=redis // change this to file
QUEUE_CONNECTION=redis // change this to sync
// I was using redis for azure cache and I missed this one because it was hard coded,
// now I placed it inside env file
AZURE_CACHE_STORE=redis // change this to file
// In fact u can skip commenting this out
#REDIS_CLIENT=predis
#REDIS_HOST=redis
#REDIS_PASSWORD=null
#REDIS_PORT=6379
无需在config/app. php中评论或删除Redis
如果您计划以后简单地切换redis,则无需删除在将来需要它的文件中使用Redis;
。在生产中,最好完全删除这些。
与phpredis
或predis
相同,如果您以后使用它,则无需删除它们。
这里的关键是检查你所有的配置,以便更好地了解谁的redis,或者只是使用你的文本编辑器,只需用redis关键字搜索所有文件。