在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set

1、在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set。如图1

图1

*** applying m191113_084655_sync_redis_wx_auth_data_to_mysql
Exception: Redis error: ERR Client sent AUTH, but no password is set
Redis command was: AUTH Redis (E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php:821)
#0 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(789): yii\redis\Connection->parseResponse(Array, '*2\r\n$4\r\nAUTH\r\n$...')
#1 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(772): yii\redis\Connection->sendCommandInternal('*2\r\n$4\r\nAUTH\r\n$...', Array)
#2 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(634): yii\redis\Connection->executeCommand('AUTH', Array)
#3 E:\wwwroot\channel-pub-api\console\migrations\m191113_084655_sync_redis_wx_auth_data_to_mysql.php(27): yii\redis\Connection->open()
#4 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\db\Migration.php(114): m191113_084655_sync_redis_wx_auth_data_to_mysql->safeUp()
#5 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(725): yii\db\Migration->up()
#6 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(200): yii\console\controllers\BaseMigrateController->migrateUp('m191113_084655_...')
#7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#8 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#9 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Controller.php(164): yii\base\Controller->runAction('', Array)
#11 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
#12 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
#13 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
#14 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 E:\wwwroot\channel-pub-api\yii(23): yii\base\Application->run()
#16 {main}
*** failed to apply m191113_084655_sync_redis_wx_auth_data_to_mysql (time: 0.011s)

2、打开终端并连接 redis-cli,测试 AUTH Redis。报错:(error) ERR Client sent AUTH, but no password is set

PS E:\wwwroot\channel-pub-api> redis-cli
127.0.0.1:6379> AUTH Redis
(error) ERR Client sent AUTH, but no password is set
127.0.0.1:6379>

3、编辑 redis.windows.conf 与 redis.windows-service.conf ,添加 requirepass Redis。

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass Redis

4、在 Windows 10 中,停止与启动 Redis

PS E:\wwwroot\channel-pub-api> redis-server --service-stop
[29528] 30 Mar 14:04:24.076 # Redis service successfully stopped.
PS E:\wwwroot\channel-pub-api> redis-server --service-start
[28132] 30 Mar 14:04:34.748 # Redis service successfully started.

5、打开终端并连接 redis-cli,测试 AUTH Redis。响应 OK。如图2

图2

PS E:\wwwroot\channel-pub-api> redis-cli
127.0.0.1:6379> AUTH Redis
OK
127.0.0.1:6379>

6、在 Yii 2.0 的数据库迁移时迁移成功。如图3

图3

*** applying m191113_084655_sync_redis_wx_auth_data_to_mysql
*** applied m191113_084655_sync_redis_wx_auth_data_to_mysql (time: 0.266s)
永夜