redis db切換錯誤
在cogfig/redis里面配置了 多個redis 鏈接
.env 文件
業(yè)務(wù)中使用 配置的單獨(dú)的 pixel 配置
期待結(jié)果 :
數(shù)據(jù)能寫到 pixel 鏈接配置的 11號數(shù)據(jù)庫
實(shí)際結(jié)果:
數(shù)據(jù)寫到了 default 鏈接配置的 0 號數(shù)據(jù)庫
正常的啟動:
php start.php start -d
數(shù)據(jù)寫入正確;
bug復(fù)現(xiàn)的步驟
1、webman 所在服務(wù)器 直接重啟
2、被 服務(wù)器配置的 crontab shell 腳本自動拉起
3、數(shù)據(jù)寫入錯誤
4、執(zhí)行 php start.php reload 后 問題解決、 數(shù)據(jù)寫入正確
這是 shell 腳本
系統(tǒng)環(huán)境等信息:
vlucas/phpdotenv 這個庫在PHP TS版本(線程安全版本)可能會有bug,請使用NTS版本(非線程安全版本)。
當(dāng)前php是什么版本可以通過執(zhí)行 php -v 查看。
如果php線程版本沒問題,嘗試打印下 config('redis');
看下配置是否正確。
感謝老大的回復(fù):
php 版本如下:
PHP 7.3.31 (cli) (built: Sep 25 2021 15:44:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.31, Copyright (c) 1999-2018, by Zend Technologies
現(xiàn)在使用 config('redis') 打印結(jié)果是正常的:
array:4 [
"default" => array:4 [
"host" => "r-xxxxx.redis.rds.aliyuncs.com"
"password" => ""
"port" => "6379"
"database" => "0"
]
"pixel" => array:4 [
"host" => "r-xxxx.redis.rds.aliyuncs.com"
"password" => ""
"port" => "6379"
"database" => "11"
]
"java-redis" => array:4 [
"host" => "r-xxxx.redis.rds.aliyuncs.com"
"password" => ""
"port" => "6379"
"database" => "5"
]
"sls-redis" => array:4 [
"host" => "r-xxxx.redis.rds.aliyuncs.com"
"password" => ""
"port" => "6379"
"database" => "0"
]
]