zoon / requeue
Redis delayed message queue without locks
Installs: 12 838
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 13
Forks: 0
Open Issues: 2
Requires
- php: >=8.1
- ext-redis: *
This package is auto-updated.
Last update: 2024-03-13 12:42:26 UTC
README
Redis delayed message queue without locks.
Quick start
Install
composer require zoon/requeue
Note: Requires Redis >= 2.2.0
Example
Initialize
$redis = new \Redis(); if (!$redis->connect('127.0.0.1')) { exit('no connection'); } $queue = createQueue($redis); function createQueue(\Redis $connection): \Zoon\ReQueue\Queue { $redisAdapter = new \Zoon\ReQueue\RedisAdapter($connection); return new \Zoon\ReQueue\Queue($redisAdapter); }
Push
$queue->push(new \Zoon\ReQueue\Message('id', time() + 3600, 'data'));
Update
$queue->update('id', function (?\Zoon\ReQueue\Message $old) { $time = ($old === null ? time() + 3600 : $old->getTimestamp() + 600); $data = ($old === null ? 'data' : $old->getData() . '+new'); return new \Zoon\ReQueue\MessageData($time, $data); });
Count
printf("count: %d\n", $queue->count());
// count: 1
Pop
$timestampRange = new \Zoon\ReQueue\TimestampRange(null, time() + 3600 + 600); $message = $queue->pop($timestampRange); if ($message !== null) { printf("id: %s\n", $message->getId()); printf("timestamp: %d\n", $message->getTimestamp()); printf("data: %s\n", $message->getData()); }
// id: id // timestamp: 1575040030 // data: data+new
Clear
$queue->clear();