|
@@ -8,23 +8,45 @@ class Redis
|
|
|
{
|
|
|
private $db;
|
|
|
|
|
|
+ private $key;
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
- $this->db = Dever::db('queue/data');
|
|
|
+ $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'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function key()
|
|
|
+ {
|
|
|
+ if ($this->key) {
|
|
|
+ return $this->key;
|
|
|
+ }
|
|
|
+ return DEVER_PROJECT . '_' . DEVER_APP_NAME;
|
|
|
}
|
|
|
|
|
|
public function push($value)
|
|
|
{
|
|
|
- $data = array('add_value' => $value);
|
|
|
- return $this->db->insert($data);
|
|
|
+ return $this->db->rpush($this->key(), $value);
|
|
|
}
|
|
|
|
|
|
public function pop()
|
|
|
{
|
|
|
- $data = $this->db->one();
|
|
|
+ $data = $this->db->lpop($this->key());
|
|
|
if ($data) {
|
|
|
- $this->db->delete($data['id']);
|
|
|
- return $data['value'];
|
|
|
+ return $data;
|
|
|
}
|
|
|
return false;
|
|
|
}
|