rabin преди 7 години
ревизия
42513d793a
променени са 7 файла, в които са добавени 177 реда и са изтрити 0 реда
  1. 10 0
      common.php
  2. 50 0
      database/data.php
  3. 7 0
      index.php
  4. 20 0
      src/Data.php
  5. 31 0
      src/Db.php
  6. 28 0
      src/Queue.php
  7. 31 0
      src/Redis.php

+ 10 - 0
common.php

@@ -0,0 +1,10 @@
+<?php
+
+function reg()
+{
+	$queue = new Queue\Src\Queue();
+	Dever::reg('push', $queue);
+	Dever::reg('pop', $queue);
+}
+
+reg();

+ 50 - 0
database/data.php

@@ -0,0 +1,50 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'data',
+	# 显示给用户看的名称
+	'lang' => '队列数据表',
+	'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+	
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+			'order'		=> 'desc',
+		),
+
+		'value'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '数据',
+			'default' 	=> '',
+			'desc' 		=> '数据',
+			'match' 	=> 'is_string',
+			//'update'	=> 'editor',
+			'search'	=> 'fulltext',
+			//'list'		=> 'Dever::load("spider/data.value", {id})',
+			//'modal'		=> '查看详情',
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			//'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+);

+ 7 - 0
index.php

@@ -0,0 +1,7 @@
+<?php
+
+define('DEVER_APP_NAME', 'queue');
+define('DEVER_APP_LANG', '队列');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', -9);
+include(DEVER_APP_PATH . '../boot.php');

+ 20 - 0
src/Data.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Queue\Src;
+
+use Dever;
+
+class Data
+{
+	private $data = array();
+
+	public function push($value)
+	{
+		return array_push($this->data, $value);
+	}
+
+	public function pop()
+	{
+		return array_shift($this->data);
+	}
+}

+ 31 - 0
src/Db.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Queue\Src;
+
+use Dever;
+
+class Db
+{
+	private $db;
+
+	public function __construct()
+	{
+		$this->db = Dever::db('queue/data');
+	}
+
+	public function push($value)
+	{
+		$data = array('add_value' => $value);
+		return $this->db->insert($data);
+	}
+
+	public function pop()
+	{
+		$data = $this->db->one();
+		if ($data) {
+			$this->db->delete($data['id']);
+			return $data['value'];
+		}
+		return false;
+	}
+}

+ 28 - 0
src/Queue.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Queue\Src;
+
+use Dever;
+
+class Queue
+{
+	private $method;
+
+	public function __construct()
+	{
+		$method = 'Queue\\Src\\' . ucfirst(Dever::config('base')->queue['method']);
+		$this->method = new $method();
+	}
+
+	public function push($value)
+	{
+		$value = json_encode($value);
+		$this->method->push($value);
+	}
+
+	public function pop()
+	{
+		$data = $this->method->pop();
+		return json_decode($data, true);
+	}
+}

+ 31 - 0
src/Redis.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Queue\Src;
+
+use Dever;
+
+class Redis
+{
+	private $db;
+
+	public function __construct()
+	{
+		$this->db = Dever::db('queue/data');
+	}
+
+	public function push($value)
+	{
+		$data = array('add_value' => $value);
+		return $this->db->insert($data);
+	}
+
+	public function pop()
+	{
+		$data = $this->db->one();
+		if ($data) {
+			$this->db->delete($data['id']);
+			return $data['value'];
+		}
+		return false;
+	}
+}