https://github.com/zoonru/requeue
https://github.com/zoonru/requeue
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zoonru/requeue
- Owner: zoonru
- License: gpl-3.0
- Archived: true
- Created: 2019-11-28T16:06:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-15T09:03:56.000Z (over 2 years ago)
- Last Synced: 2024-12-17T09:15:04.696Z (over 1 year ago)
- Language: PHP
- Size: 22.5 KB
- Stars: 1
- Watchers: 13
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ReQueue
Redis delayed message queue without locks.
# Quick start
## Install
```bash
composer require zoon/requeue
```
Note: Requires Redis >= 2.2.0
## Example
**Initialize**
```php
$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**
```php
$queue->push(new \Zoon\ReQueue\Message('id', time() + 3600, 'data'));
```
**Update**
```php
$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**
```php
printf("count: %d\n", $queue->count());
```
```php
// count: 1
```
**Pop**
```php
$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());
}
```
```php
// id: id
// timestamp: 1575040030
// data: data+new
```
**Clear**
```php
$queue->clear();
```