1、在 Yii 2.0 的控制台命令中,报错:yii/db/Exception: Redis error: ERR invalid DB index
Redis command was: SELECT 29 in /vendor/yiisoft/yii2-redis/src/Connection.php:736,查看 /console/runtime/logs/app.log
2019-08-09 09:44:13 [-][-][-][error][yii/db/Exception] yii/db/Exception: Redis error: ERR invalid DB index Redis command was: SELECT 29 in /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php:736 Stack trace: #0 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(713): yii/redis/Connection->parseResponse('SELECT 29') #1 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(697): yii/redis/Connection->sendCommandInternal('*2/r/n$6/r/nSELECT/r...', Array) #2 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(559): yii/redis/Connection->executeCommand('SELECT', Array) #3 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(665): yii/redis/Connection->open() #4 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(630): yii/redis/Connection->executeCommand('SET', Array) #5 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php(135): yii/redis/Connection->__call('set', Array) #6 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php(59): yii/queue/redis/Queue->reserve(3) #7 [internal function]: yii/queue/redis/Queue->yii/queue/redis/{closure}(Object(Closure)) #8 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-queue/src/cli/Queue.php(117): call_user_func(Object(Closure), Object(Closure)) #9 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php(68): yii/queue/cli/Queue->runWorker(Object(Closure)) #10 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-queue/src/drivers/redis/Command.php(76): yii/queue/redis/Queue->run(true, 3) #11 [internal function]: yii/queue/redis/Command->actionListen(3) #12 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #13 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/base/Controller.php(157): yii/base/InlineAction->runWithParams(Array) #14 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/console/Controller.php(148): yii/base/Controller->runAction('listen', Array) #15 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/base/Module.php(528): yii/console/Controller->runAction('listen', Array) #16 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/console/Application.php(180): yii/base/Module->runAction('upload-asset-qu...', Array) #17 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/console/Application.php(147): yii/console/Application->runAction('upload-asset-qu...', Array) #18 /sobey/www/channel-pub-api/vendor/yiisoft/yii2/base/Application.php(386): yii/console/Application->handleRequest(Object(yii/console/Request)) #19 /sobey/www/channel-pub-api/yii(23): yii/base/Application->run() #20 {main}
2、分析发现,是在执行命令:SELECT 29 时,切换到相应数据库:29 时报错的,一个 redis 实例默认有 16 个数据库,从 0 – 15,超出这个范围就会报 ERR invalid DB index,如图1
#0 /sobey/www/channel-pub-api/vendor/yiisoft/yii2-redis/src/Connection.php(713): yii/redis/Connection->parseResponse('SELECT 29')
3、编辑 redis.windows.conf 与 redis.windows-service.conf 文件,查找:databases 16,修改为:databases 32
# Set the number of databases. The default database is DB 0, you can select # a different one on a per-connection basis using SELECT <dbid> where # dbid is a number between 0 and 'databases'-1 databases 32
4、在 Windows 10 中,停止与启动 Redis
PS C:/> redis-server --service-stop [87292] 09 Aug 10:44:18.772 # Redis service successfully stopped. PS C:/> redis-server --service-start [77236] 09 Aug 10:44:31.673 # Redis service successfully started.
5、打开 RedisDesktopManager,数量变化为 20,但是已经可以执行 SELECT 0 – 31 的命令,如图2
6、删除连接,新连接设置 – 高级设置 – 数据库发现限制,其值默认为 20 ,编辑为 32,如图3
7、打开 RedisDesktopManager,数量变化为 32,符合预期,如图4
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250476.html