123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- class Task_MQ_KeyValue implements Task_MQ {
-
- protected $kvCache;
- public function __construct(PhalApi_Cache $kvCache) {
- $this->kvCache = $kvCache;
- }
- public function add($service, $params = array()) {
- $list = $this->kvCache->get($service);
- if (empty($list)) {
- $list = array();
- }
- $list[] = $params;
- $this->kvCache->set($service, $list, $this->getExpireTime());
- $list = $this->kvCache->get($service);
- return true;
- }
- public function pop($service, $num = 1) {
- $rs = array();
- if ($num <= 0) {
- return $rs;
- }
- $list = $this->kvCache->get($service);
- if (empty($list)) {
- $list = array();
- }
- $rs = array_splice($list, 0, $num);
- $this->kvCache->set($service, $list, $this->getExpireTime());
- return $rs;
- }
-
- protected function getExpireTime() {
- return 31536000;
- }
- }
|