【问题标题】:Removing Redis from Laravel Project in Windows在 Windows 中从 Laravel 项目中删除 Redis
【发布时间】:2019-12-12 01:53:10
【问题描述】:

如果没有 Redis 运行,我的项目将无法启动。如果我尝试在 Laravel 中没有运行 redis 的情况下打开页面,我会收到此消息:

“由于目标机器主动拒绝,无法建立连接。[tcp://127.0.0.1:6379]”

我试过了 1)php工匠配置:缓存, 2)php工匠清除:缓存, 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 并尝试重新加载页面时 - 它给了我这个错误:找不到 Class 'Predis\Client'
  • 只使用文件缓存驱动,它不依赖于文件系统。见laravel.com/docs/5.8/cache
  • 谢谢,但我目前正在使用我的 cache.php 文件中的文件缓存驱动程序,但仍然出现相同的错误。

标签: php laravel redis predis


【解决方案1】:

我刚才也遇到了同样的问题。错误:

“由于目标机器主动拒绝,无法建立连接。[tcp://127.0.0.1:6379]”

这意味着应用中的某些东西仍在使用 redis 提供服务。

  1. 检查控制器和/或模型的 redis 连接或 redis 方法并删除所有这些。
  2. 在配置中,您要检查缓存、数据库、队列和文件系统。为此,请确保您的 env 文件中没有任何与 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,则无需在将来需要它的文件中删除 use Redis;。在生产中最好完全删除这些。

phpredispredis 相同,如果您以后使用它们,则无需删除它们。

这里的关键是检查你的所有配置,以更好地了解谁的 redis 东西在哪里,或者只需使用文本编辑器,只需使用 redis 关键字搜索所有文件。

【讨论】:

    【解决方案2】:

    如果你不想安装任何缓存服务,如 RedisMemcached,你可以在 Laravel 上使用 filedatabase 驱动。 p>

    要更改缓存驱动程序,您必须将.env 文件中的CACHE_DRIVER 变量更改为file,或修改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

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多