Redis和Laravel - 数据库[redis]未配置

3
好的,这几天我一直在配置我的Laravel应用程序在pagodabox上运行。但是我遇到了一个问题。我刚刚推送了我的代码,首页可以加载,但当我尝试注册新用户或使用php artisan migrate迁移数据库时,我会遇到以下错误:

未配置数据库[redis]。

我正在使用Pagodabox。需要花费几天时间来掌握他们的配置,但我已经弄清楚了。我该怎么做才能配置Redis?我查看了文档,并且已经成功让Laravel连接到服务器,因为我的首页可以加载。我是否漏掉了什么步骤?我在谷歌上搜索了一下,但没有找到答案。如何配置我的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中的connections数组。没有redis数组。我现在正在查找要放入connections数组中的内容。

 '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 文件中的一部分 (https://laravel.com/docs/5.3/redis)。 - phaberest
请发布您的 config/database.php 和 .env 文件的内容。 - Paras
你的 Redis 服务器正在运行吗? - Matthias Weiß
不确定,我的主机不让我SSH到我的数据库服务器... - Tom Morison
你能在config/database.php文件中发布你的connections数组吗?我怀疑该数组中没有定义redis。 - Paras
显示剩余3条评论
2个回答

1
我们遇到了同样的问题。在我们的情况下,罪魁祸首在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

希望能对您有所帮助。


0

谁遇到了这个错误,但是没有成功解决它:

php artisan clear-compiled
composer dump-autoload

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

为什么这个修复方法解决了错误? - Witt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接