2 Star 9 Fork 1

GaoJiuFeng / EasyQueue

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

EasyQueue简单易用PHP-Redis队列,支持延迟队列

队列介绍

基于Redis有序集合实现的Redis延迟队列,添加/删除/查找的复杂度都是 O(1),每个队列中可存储40多亿元素。

环境依赖

"php": ">=5.4"
"ext-redis": ">=2.0"

Composer安装

  composer require easy-queue/easy-queue

【A】. 快速入门->生产者(延迟队列)
//加载Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

//创建easy-queue对象
$queue = new Queue($redis);

//向seo_link延迟队列中投递数据(30秒后处理)
$name = 'seo_link';
$value = json_encode([
    'article_id' => $_GET['article_id'],
    'add_time' => time(),
]);
$time = time() + 30;
$res = $queue->add($name, $value, $time);
if ($res)
{
    echo '投递成功';
}
else
{
    echo '投递失败';
}

【B】. 快速入门->消费者(延迟队列)
//加载Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

//创建easy-queue对象
$queue = new Queue($redis);

//从seo_link延迟队列中取出到期的数据
$name = 'seo_link';
$value = $queue->get($name);
if ($value)
{
    $value = json_decode($value, true);
    var_dump($value);
}

【C】. 快速入门->消费者参数解释
消费者函数get方法参数说明:
$name:传递要消费的延迟队列名称
$e_time:获取队列中到期时间小于等于$e_time的数据
$s_time:获取队列中到期时间大于等于$s_time的数据
$limit:获取多少条数据,如果大于1条则返回二维数组,否则返回一维数组
$remove:设置获取后是否删除队列中的值,默认为删除
(1).在队列中查询time<=1603597141 and time>=0 的元素(同时队列中会自动删除符合条件的元素)
$time = 1603597141;
$list = $queue->get($time);

(2).在队列中查询time<=1603597413 and time>=1603597132 的元素(同时队列中会自动删除符合条件的元素)
$time1 = 1603597413;
$time2 = 1603597132;
$list = $queue->get($time1, $time2);

(3).在队列中查询time<=1603597555 and time>=1603597132 的元素,只返回1条(同时队列中会自动删除这条元素)
$time1 = 1603597555;
$time2 = 1603597132;
$list = $queue->get($time1, $time2,1);

(4).在队列中查询time<=1603597693 and time>=1603597132 的元素返回10条即可,不删除队列数据,仅查看数据
$time1 = 1603597693;
$time2 = 1603597132;
$list = $queue->get($time1, $time2, 10, false);

【D】. 快速入门->消费者(普通队列)
......

【E】. Bug反馈
请反馈至QQ392223903,感谢持续反馈!

Repository Comments ( 0 )

Sign in to post a comment

About

简单易用的PHP-Reids延迟队列 expand collapse
PHP
MIT
Cancel

Releases (1)

All

EasyQueue

Contributors

All

Activities

Load More
can not load any more
PHP
1
https://git.oschina.net/392223903/easy-queue.git
git@git.oschina.net:392223903/easy-queue.git
392223903
easy-queue
EasyQueue
master

Search