【问题标题】:Redis and Laravel - Database [redis] not configuredRedis 和 Laravel - 未配置数据库 [redis]
【发布时间】:2017-05-30 03:44:48
【问题描述】:

好吧,这已经很长几天了,但我几乎已经在 pagodabox 上配置了我的 Laravel 应用程序。我遇到了一个问题。我刚刚推送了我的代码,并且主页加载了,但是当我尝试注册新用户或使用 php artisan migrate 迁移数据库时,出现以下错误;

数据库 [redis] 未配置。

我正在使用 Pagodabox。掌握他们的配置需要几天的时间,但我已经弄清楚了。我需要做什么来配置 Redis?我检查了the documentaton,我已经能够让 Laravel 连接到服务器没问题,因为我的主页加载了。我错过了一步吗?我google了一下,没有找到答案。如何配置我的 Redis 数据库?

编辑:

   <?php

return [

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    'fetch' => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'redis'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'CSToss'),
            'username' => env('DB_USERNAME', 'homestead'),
            'password' => env('DB_PASSWORD', 'secret'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
        ],




    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'cluster' => false,

        'default' => [
            'host' => env('REDIS_HOST', '192.168.0.3'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];

和 .env:

APP_ENV=local
APP_KEY=base64:oHPYI6XIKowuqfhZaLhWayKSc5bw1XlnvFKIwWZAieI=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=redis
DB_HOST=http://192.168.0.3
DB_PORT=6379
DB_DATABASE=cryptoflipdb
DB_USERNAME=
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=192.168.0.3
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

编辑:这是我来自 config/database.php 的连接数组。没有redis数组。我现在正在查找要在连接数组中放入的内容

 'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'CSToss'),
            'username' => env('DB_USERNAME', 'homestead'),
            'password' => env('DB_PASSWORD', 'secret'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
        ],

【问题讨论】:

  • 确保您已将 redis 配置为您的 .env 和您的 config/database.php (laravel.com/docs/5.3/redis)
  • 请发布您的 config/database.php 和 .env 文件的内容
  • 你的redis服务器运行了吗?
  • 不确定,我的主机不允许我通过 SSH 连接到我的数据库服务器...
  • 你能在config/database.php中发布你的连接数组吗?我怀疑这个数组中没有定义redis

标签: php laravel


【解决方案1】:

谁有这个错误并且没有运气修复它:

php artisan clear-compiled
composer dump-autoload

我在尝试使用另一个数据库进行测试时遇到此错误 (.env.testing) 希望它也能解决您的问题。

【讨论】:

    【解决方案2】:

    我们遇到了同样的问题。在我们的例子中,罪魁祸首是config/sessions.php

    /*
    |--------------------------------------------------------------------------
    | Session Database Connection
    |--------------------------------------------------------------------------
    |
    | When using the "database" or "redis" session drivers, you may specify a
    | connection that should be used to manage these sessions. This should
    | correspond to a connection in your database configuration options.
    |
    */
    
    'connection' => 'mysql',
    

    这仅在您使用数据库会话驱动程序时有效。如果要使用redis,则必须将其更改为redis的正确连接名称。在我们的例子中,这是default

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-07-21
      • 1970-01-01
      • 2020-11-27
      • 2019-04-22
      • 1970-01-01
      • 2021-07-02
      • 2021-02-21
      • 2022-10-23
      • 1970-01-01
      相关资源
      最近更新 更多