公共方法

This commit is contained in:
chengxl
2025-07-22 16:40:27 +08:00
parent 41063dfd06
commit fb7db7aaa1
5 changed files with 373 additions and 476 deletions

View File

@@ -34,9 +34,12 @@ class QueueRedis
$this->config['host'] ?? '127.0.0.1',
$this->config['port'] ?? 6379
);
// 始终执行认证(空密码会被 Redis 忽略)
$this->redis->auth($this->config['password'] ?? '');
if (!empty($this->config['password'])) {
$this->redis->auth($this->config['password']);
}
$this->redis->select($this->config['select'] ?? 0);
}
@@ -149,7 +152,7 @@ LUA;
'completed' => 0,
'start_time' => time()
]);
$redis->expire($key, 21600); // 6小时过期
$redis->expire($key, 10800); // 6小时过期
return true;
} catch (\Exception $e) {
return false;
@@ -185,7 +188,7 @@ LUA;
$redis = $this->connect();
$redis->hSet($key, "chunk_{$chunkIndex}", $content);
// 确保设置过期时间(如果已设置则忽略)
$redis->expire($key, 21600);
$redis->expire($key, 10800);
return true;
}
@@ -202,7 +205,7 @@ LUA;
public function getConnectionStatus()
{
try {
return $this->connect()->ping() === '+PONG';
return $this->connect()->ping();
} catch (\Exception $e) {
return false;
}