2 Star 13 Fork 3

GaoJiuFeng / EasyQueue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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,感谢持续反馈!
MIT License Copyright (c) 2020 GaoJiuFeng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

简单易用的PHP-Reids延迟队列 展开 收起
PHP
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/392223903/easy-queue.git
git@gitee.com:392223903/easy-queue.git
392223903
easy-queue
EasyQueue
master

搜索帮助