123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace Queue\Src;
- use Dever;
- class Redis implements QueueInterface
- {
- private $db;
- public function __construct()
- {
- $this->db = new \Redis;
- $config = Dever::config('base')->queue;
- $host = Dever::config('base')->queue['host'];
- $port = Dever::config('base')->queue['port'];
- $this->db->connect($config['host'], $config['port']);
- if (isset($config['password'])) {
- $this->db->auth($config['password']);
- }
- if (isset($config['key']) && $config['key']) {
- $this->key = $config['key'];
- }
- }
- public function push($value, $key)
- {
- return $this->db->rpush($key, $value);
- }
- public function pop($key)
- {
- $data = $this->db->lpop($key);
- if ($data) {
- return $data;
- }
- return false;
- }
- public function len($key)
- {
- return $this->db->llen($key);
- }
- }
|