Skip to content

Commit c19f9a2

Browse files
authored
Fixed bug that message will be lost when unpack failed. (#6516)
1 parent d3ca488 commit c19f9a2

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/Driver/RedisDriver.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ public function pop(): array
8585
}
8686

8787
$data = $res[1];
88+
89+
$this->redis->zadd($this->channel->getReserved(), time() + $this->handleTimeout, $data);
90+
8891
$message = $this->packer->unpack($data);
8992
if (! $message) {
9093
return [false, null];
9194
}
9295

93-
$this->redis->zadd($this->channel->getReserved(), time() + $this->handleTimeout, $data);
94-
9596
return [$data, $message];
9697
}
9798

src/JobMessage.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public function __serialize(): array
2929
$this->job = $this->job->compress();
3030
}
3131

32-
return [
33-
'job' => $this->job,
34-
'attempts' => $this->attempts,
35-
];
32+
return [$this->job, $this->attempts];
3633
}
3734

3835
public function __unserialize(array $data): void

tests/JobMessageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testJobMessageSerializeCompatible()
5353
$serialized = $message->__serialize();
5454

5555
$serialized = [
56-
'job' => $serialized['job'],
56+
'job' => $serialized['job'] ?? $serialized[0],
5757
'attempts' => 3,
5858
];
5959
$message->__unserialize($serialized);

0 commit comments

Comments
 (0)