加redis日志
This commit is contained in:
@@ -1281,6 +1281,22 @@ function getMillisecond() {
|
||||
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* 写入日志到redis
|
||||
* @param string $key 日志key
|
||||
* @param array $logData 日志数据
|
||||
*/
|
||||
function write_log_redis($key = 'log',$logData = [],$time = 7){
|
||||
$redis = new \Redis();
|
||||
// 连接到Redis服务器
|
||||
$redis->connect(config('redis.host'), config('redis.port')); // 根据实际配置调整主机和端口
|
||||
// 选择数据库2
|
||||
$redis->select(2);
|
||||
$key = $key.'_'.date('Y-m-d-H-i-s');
|
||||
$expire = 86400 * $time;
|
||||
$redis->setex($key, $expire, json_encode($logData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user