first commit
This commit is contained in:
189
ZeedFramework/library/Zeed/Db/Model/Detach.php
Normal file
189
ZeedFramework/library/Zeed/Db/Model/Detach.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_Db
|
||||
* @subpackage Zeed_Db_Model
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2010-7-5
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Zeed_Db_Model_Detach extends Zeed_Db_Model
|
||||
{
|
||||
/**
|
||||
* table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_table_name = null;
|
||||
|
||||
/**
|
||||
* 定义分表依据字段
|
||||
*
|
||||
* @var $_detachField string
|
||||
* @overwrite
|
||||
*/
|
||||
protected $_detachField = '';
|
||||
|
||||
/**
|
||||
* 数据分表数
|
||||
* 指定的值是多少,分出的表就有多少。
|
||||
*
|
||||
* @var $_detachNum integer
|
||||
*/
|
||||
protected $_detachNum = 1;
|
||||
|
||||
/**
|
||||
* 强制跳过 crc32 加密
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
protected $_skipCrc32 = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array|null
|
||||
* @see database.table_detach
|
||||
*/
|
||||
private static $_detachConfig = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var $_detachToken string
|
||||
*/
|
||||
protected $_detachToken = null;
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->_table_name = $this->_name;
|
||||
|
||||
parent::__construct($config);
|
||||
|
||||
/**
|
||||
* load configure
|
||||
*/
|
||||
if ( ! is_string($this->_detachField) || '' == $this->_detachField ) {
|
||||
throw new Zeed_Exception('Detach Field was not defined. you must overwirte the variable $_detachField in your model.');
|
||||
}
|
||||
|
||||
if ( null !== $this->_detachNum) {
|
||||
if ( false === self::$_detachConfig) {
|
||||
self::$_detachConfig = Zeed_Config::loadGroup('database.table_detach');
|
||||
}
|
||||
|
||||
if ( null === self::$_detachConfig || ! isset(self::$_detachConfig[$this->_table_name]) ) {
|
||||
throw new Zeed_Exception($this->_table_name . 'Detach config was not defined. check to see database.php in config.');
|
||||
}
|
||||
|
||||
$this->_detachNum = self::$_detachConfig[$this->_table_name];
|
||||
}
|
||||
}
|
||||
|
||||
public function format($value)
|
||||
{
|
||||
$value = (int) $value;
|
||||
|
||||
if (function_exists('bcmod')) {
|
||||
return bcmod($value, $this->_detachNum);
|
||||
} else {
|
||||
return $value % $this->_detachNum;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分表依据字段整型值,用于分表运算
|
||||
*
|
||||
* @param string $field
|
||||
* @return integer|null
|
||||
* @overwrite
|
||||
*/
|
||||
protected function getDetcahFieldForMod($value)
|
||||
{
|
||||
$forMod = null;
|
||||
|
||||
if (is_int($value)) {
|
||||
$forMod = $value;
|
||||
} elseif (is_string($value) && ! $this->_skipCrc32) {
|
||||
$checksum = crc32($value);
|
||||
$forMod = sprintf("%u", $checksum);
|
||||
} else {
|
||||
$forMod = $value;
|
||||
}
|
||||
|
||||
return $forMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分表表名因子
|
||||
*
|
||||
* @param mixed 查询数据库条件数据、更新数据
|
||||
* @return void
|
||||
*/
|
||||
public function detachToken($data)
|
||||
{
|
||||
if ('' == $this->_detachField) {
|
||||
throw new Zeed_Exception('must specify a valid field for detcah table');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
if (is_array($data) && ! empty($data[$this->_detachField])) {
|
||||
$i = $this->getDetcahFieldForMod($data[$this->_detachField]);
|
||||
} elseif ($data instanceof Zeed_Object) {
|
||||
$d = $data->toArray();
|
||||
if (! empty($d[$this->_detachField])) {
|
||||
$i = $this->getDetcahFieldForMod($d[$this->_detachField]);
|
||||
}
|
||||
} elseif (is_string($data) || is_numeric($data) || is_integer($data)) {
|
||||
$i = $this->getDetcahFieldForMod($data);
|
||||
}
|
||||
|
||||
$formatted = $this->format($i);
|
||||
$this->setDetachToken($formatted);
|
||||
}
|
||||
|
||||
public function getDetachToken()
|
||||
{
|
||||
return $this->_detachToken;
|
||||
}
|
||||
|
||||
public function setDetachToken($token) {
|
||||
$token = (int) $token;
|
||||
|
||||
if ($token >= 0 && $token <= 1000) {
|
||||
$num = strlen(strval($this->_detachNum - 1));
|
||||
$this->_detachToken = sprintf("%0{$num}u", $token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
if ( null !== $this->_detachToken) {
|
||||
return $this->_name.'_'.$this->_detachToken;
|
||||
}
|
||||
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createDetachTable($tables) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
116
ZeedFramework/library/Zeed/Db/Model/Detach/Date.php
Normal file
116
ZeedFramework/library/Zeed/Db/Model/Detach/Date.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2010-8-11
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Zeed_Db_Model_Detach_Date extends Zeed_Db_Model_Detach
|
||||
{
|
||||
/**
|
||||
* table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_table_name = null;
|
||||
|
||||
/**
|
||||
* 定义分表依据字段
|
||||
*
|
||||
* @var $_detachField string
|
||||
* @overwrite
|
||||
*/
|
||||
protected $_detachField = '';
|
||||
|
||||
/**
|
||||
* 数据分表数
|
||||
* 指定的值是多少,分出的表就有多少。
|
||||
*
|
||||
* @var $_detachNum integer
|
||||
*/
|
||||
protected $_detachNum = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var $_detachToken string
|
||||
*/
|
||||
protected $_detachToken = null;
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->_table_name = $this->_name;
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
public function getDetcahFieldForDate($value)
|
||||
{
|
||||
if (is_numeric($value) || is_integer($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$forDate = strtotime($value);
|
||||
if (!$forDate) {
|
||||
$forDate = 0;
|
||||
}
|
||||
|
||||
return $forDate;
|
||||
}
|
||||
|
||||
public function format($value)
|
||||
{
|
||||
if (is_integer($value) || is_numeric($value)) {
|
||||
return date('ym', $value);
|
||||
}
|
||||
|
||||
return '0000';
|
||||
}
|
||||
|
||||
public function setDetachToken($token) {
|
||||
$this->_detachToken = str_pad($token, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分表表名因子
|
||||
*
|
||||
* @param mixed 查询数据库条件数据、更新数据
|
||||
* @return void
|
||||
*/
|
||||
public function detachToken($data)
|
||||
{
|
||||
if ('' == $this->_detachField) {
|
||||
throw new Zeed_Exception('must specify a valid field for detcah table');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
if (is_array($data) && ! empty($data[$this->_detachField])) {
|
||||
$i = $this->getDetcahFieldForDate($data[$this->_detachField]);
|
||||
} elseif ($data instanceof Zeed_Object) {
|
||||
$d = $data->toArray();
|
||||
if (! empty($d[$this->_detachField])) {
|
||||
$i = $this->getDetcahFieldForMod($d[$this->_detachField]);
|
||||
}
|
||||
} elseif (is_numeric($data) || is_integer($data)) {
|
||||
$i = $data;
|
||||
} else {
|
||||
$i = $this->getDetcahFieldForDate($data);
|
||||
}
|
||||
|
||||
$this->_detachToken = $this->format($i);
|
||||
}
|
||||
}
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
131
ZeedFramework/library/Zeed/Db/Model/Mongo.php
Normal file
131
ZeedFramework/library/Zeed/Db/Model/Mongo.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2011-5-18
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Zeed_Db_Model_Mongo
|
||||
{
|
||||
/**
|
||||
* @var Mongo
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* @var MongoDb
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var MongoCollection
|
||||
*/
|
||||
protected $collection = null;
|
||||
|
||||
/**
|
||||
* 数据库表前缀(系统内部使用)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_prefix = null;
|
||||
|
||||
/**
|
||||
* 数据库连接实例缓存
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $instanceInternalCache = array();
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$config = Zeed_Config::loadGroup('database.mongodb');
|
||||
|
||||
if ($this->_prefix != '') {
|
||||
$this->_name = $this->_prefix . $this->_name;
|
||||
}
|
||||
|
||||
$serverOptions = isset($config['server_options']) ? $config['server_options'] : array();
|
||||
$this->conn = $this->connect($config['server'], $serverOptions);
|
||||
$this->db = $this->conn->selectDB($config['db']);
|
||||
$this->collection = $this->db->selectCollection($this->_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库连接实例缓存
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $connections = null;
|
||||
|
||||
/**
|
||||
* @return Mongo
|
||||
*/
|
||||
protected function connect($dsn, $options)
|
||||
{
|
||||
if (! isset(self::$connections[$dsn])) {
|
||||
if (! empty($options) && is_array($options)) {
|
||||
self::$connections[$dsn] = new Mongo($dsn, $options);
|
||||
} else {
|
||||
self::$connections[$dsn] = new Mongo($dsn);
|
||||
}
|
||||
}
|
||||
|
||||
return self::$connections[$dsn];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function listDBs()
|
||||
{
|
||||
return $this->conn->listDBs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function listCollections()
|
||||
{
|
||||
return $this->db->listCollections();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在子类中(注意注释中填写正确的返回值类型, 一般为类名):
|
||||
* <code>
|
||||
* public static function instance()
|
||||
* {
|
||||
* return parent::_instance(__CLASS__);
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param string $model
|
||||
* @throws Zeed_Exception
|
||||
* @return Zeed_Db_Model_Mongo
|
||||
*/
|
||||
protected static function _instance($model)
|
||||
{
|
||||
if (isset(self::$instanceInternalCache[$model]) && is_subclass_of(self::$instanceInternalCache[$model], __CLASS__)) {
|
||||
return self::$instanceInternalCache[$model];
|
||||
} elseif (class_exists($model)) {
|
||||
self::$instanceInternalCache[$model] = new $model();
|
||||
return self::$instanceInternalCache[$model];
|
||||
}
|
||||
|
||||
throw new Zeed_Exception('Mongo Model( ' . $model . ' ) not exists.');
|
||||
}
|
||||
}
|
||||
|
||||
// End ^ Native EOL ^ UTF-8
|
||||
521
ZeedFramework/library/Zeed/Db/Model/Redis.php
Normal file
521
ZeedFramework/library/Zeed/Db/Model/Redis.php
Normal file
@@ -0,0 +1,521 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2011-5-18
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Zeed_Db_Model_Redis
|
||||
{
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $_config = null;
|
||||
|
||||
/**
|
||||
* @var RedisCollection
|
||||
*/
|
||||
protected $collection = null;
|
||||
|
||||
/**
|
||||
* 数据库连接实例缓存
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $instanceInternalCache = array();
|
||||
|
||||
public function __construct ($config = array())
|
||||
{
|
||||
$this->_config = Zeed_Config::loadGroup('database.redis');
|
||||
|
||||
$this->collection = $this->connect($this->_config['host'], $this->_config['port']);
|
||||
$this->collection->select($this->_config['db']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库连接实例缓存
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $connections = null;
|
||||
|
||||
/**
|
||||
* @return Redis
|
||||
*/
|
||||
protected function connect ($host, $port)
|
||||
{
|
||||
self::$connections[$host] = new redis();
|
||||
self::$connections[$host]->connect($host, $port);
|
||||
return self::$connections[$host];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists ($key)
|
||||
{
|
||||
return $this->collection->exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param array $value/存储数据
|
||||
* @return string
|
||||
*/
|
||||
public function set ($key, $value)
|
||||
{
|
||||
$ret = $this->collection->set($key, $value);
|
||||
if (is_int($this->_config['expire']) && $this->_config['expire']) {
|
||||
$this->collection->expire($key, $this->_config['expire']);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return string
|
||||
*/
|
||||
public function get ($key, $expire = TRUE)
|
||||
{
|
||||
$ret = $this->collection->get($key);
|
||||
if ($expire && is_int($this->_config['expire']) && $this->_config['expire']) {
|
||||
$this->collection->expire($key, $this->_config['expire']);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* list 入队列 返回已进入当前队列的元素数量
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param string $value/存储值
|
||||
* @return int/执行命令后,列表的长度
|
||||
*/
|
||||
public function rpush ($key, $value)
|
||||
{
|
||||
return $this->collection->rpush($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 key 中的值自增 1
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function incr ($key)
|
||||
{
|
||||
return $this->collection->incr($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 key 中的值,自增第二个参数所填的值
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $val
|
||||
* @return string
|
||||
*/
|
||||
public function incrby ($key, $val)
|
||||
{
|
||||
return $this->collection->incrby($key, $val);
|
||||
}
|
||||
|
||||
/**
|
||||
* list 出队列
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return string
|
||||
*/
|
||||
public function lpop ($key)
|
||||
{
|
||||
return $this->collection->lpop($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* list 删除元素
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param string $value/存储值
|
||||
* @return int/被移除元素的数量
|
||||
*/
|
||||
public function lrem ($key, $value)
|
||||
{
|
||||
return $this->collection->lrem($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* list 查询队列
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param int $index/队列索引
|
||||
* 0表示第一个
|
||||
* -1表示最后一个
|
||||
* @return string
|
||||
*/
|
||||
public function lindex ($key, $index)
|
||||
{
|
||||
return $this->collection->lindex($key, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* list 遍历
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return array
|
||||
*/
|
||||
public function lrange ($key)
|
||||
{
|
||||
return $this->collection->lrange($key, 0, - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* list 返回元素的数量
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return int
|
||||
*/
|
||||
public function llen ($key)
|
||||
{
|
||||
return $this->collection->llen($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回名称为key的list有多少个元素
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return int
|
||||
*/
|
||||
public function lsize ($key)
|
||||
{
|
||||
return $this->collection->lsize($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 设置值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param array $value/存储数据
|
||||
* @return string
|
||||
*/
|
||||
public function hmset ($key, $value)
|
||||
{
|
||||
return $this->collection->hmset($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 读取值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param array $value/存储数据
|
||||
* @return string
|
||||
*/
|
||||
public function hmget ($key, $arr)
|
||||
{
|
||||
return $this->collection->hmget($key, $arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 设置值
|
||||
*
|
||||
* @param string $h
|
||||
* @param string $key
|
||||
* @param string $val
|
||||
* @return string
|
||||
*/
|
||||
public function hset ($h, $key, $val)
|
||||
{
|
||||
return $this->collection->hset($h, $key, $val);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 读取值
|
||||
*
|
||||
* @param string $h
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function hget ($h, $key)
|
||||
{
|
||||
return $this->collection->hget($h, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 读取值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return string
|
||||
*/
|
||||
public function hgetall ($key, $expire = TRUE)
|
||||
{
|
||||
$ret = $this->collection->hgetall($key);
|
||||
if ($expire && is_int($this->_config['expire']) && $this->_config['expire']) {
|
||||
$this->collection->expire($key, $this->_config['expire']);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* hash 删除 key中的一个或多个指定域,不存在的域将被忽略
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param string $field/域名
|
||||
* @return int/被成功移除的域的数量,不包括被忽略的域
|
||||
*/
|
||||
public function hdel ($key, $domain)
|
||||
{
|
||||
return $this->collection->hdel($key, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 设置值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param array $value/存储数据
|
||||
* @return int 0,1
|
||||
*/
|
||||
public function sadd ($key, $value)
|
||||
{
|
||||
return $this->collection->sadd($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 移除元素
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param array $value/元素名称
|
||||
* @return int/被成功移除的元素的数量,不包括被忽略的元素
|
||||
*/
|
||||
public function srem ($key, $value)
|
||||
{
|
||||
return $this->collection->srem($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 返回集合所有信息
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return array
|
||||
*/
|
||||
public function smembers ($key)
|
||||
{
|
||||
return $this->collection->smembers($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 返回交集信息
|
||||
*
|
||||
* @param string $arrKey/需查询的交集key
|
||||
* @return array
|
||||
*/
|
||||
public function sinter ($arrKey)
|
||||
{
|
||||
return $this->collection->sinter($arrKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 返回差集信息
|
||||
*
|
||||
* @param string $arrKey/需查询的差集key
|
||||
* @return array
|
||||
*/
|
||||
public function sdiff ($arrKey)
|
||||
{
|
||||
return $this->collection->sdiff($arrKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* set 返回并集信息
|
||||
*
|
||||
* @param string $arrKey/需查询的并集key
|
||||
* @return array
|
||||
*/
|
||||
public function sunion ($arrKey)
|
||||
{
|
||||
return $this->collection->sunion($arrKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* zset 设置值
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param string $score/存储的排序值(一般我用时间戳)
|
||||
* @param string $value/存储数据
|
||||
* @return int 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员
|
||||
*/
|
||||
public function zadd ($key, $score, $value)
|
||||
{
|
||||
return $this->collection->zadd($key, $score, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* zset 返回列表 从大到小排序
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param int $start/第几个开始显示
|
||||
* @param int $end/结束位置-1为全长度
|
||||
* @param boolean $withscores/是否显示score值
|
||||
* @return array/指定区间内,带有 score 值(可选)的有序集成员的列表
|
||||
*/
|
||||
public function zrevrange ($key, $start, $end, $withscores = FALSE)
|
||||
{
|
||||
return $this->collection->zrevrange($key, $start, $end, $withscores);
|
||||
}
|
||||
|
||||
/**
|
||||
* zset 返回列表 从小到大排序
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param int $start/第几个开始显示
|
||||
* @param int $end/结束位置-1为全长度
|
||||
* @param boolean $withscores/是否显示score值
|
||||
* @return array/指定区间内,带有 score 值(可选)的有序集成员的列表
|
||||
*/
|
||||
public function zrange ($key, $start, $end, $withscores = FALSE)
|
||||
{
|
||||
return $this->collection->zrange($key, $start, $end, $withscores);
|
||||
}
|
||||
|
||||
/**
|
||||
* zset 返回并集数据
|
||||
*
|
||||
* @param string $arrKey/需查询的并集key
|
||||
* @param int $start/第几个开始显示
|
||||
* @param int $end/结束位置-1为全长度
|
||||
* @return array
|
||||
*/
|
||||
public function zunion ($arrKey, $start, $end)
|
||||
{
|
||||
$redisData = $this->collection->multi()
|
||||
->zunionstore('tempKey', $arrKey)
|
||||
->zrevrange('tempKey', $start, $end)
|
||||
->del('tempKey')
|
||||
->exec(); // 事务模式
|
||||
return $redisData[1]; // 获取第二个命令执行的数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除键
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @param
|
||||
* @return boolean
|
||||
*/
|
||||
public function del ($key)
|
||||
{
|
||||
return $this->collection->del($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择一个数据库
|
||||
*/
|
||||
public function select($database)
|
||||
{
|
||||
$ret = $this->collection->select($database);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前数据库
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flushDB ()
|
||||
{
|
||||
return $this->collection->flushDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有数据库
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flushAll ()
|
||||
{
|
||||
return $this->collection->flushAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发表内容到某一个通道
|
||||
*/
|
||||
public function publish ($channel, $key)
|
||||
{
|
||||
$ret = $this->collection->publish($channel, $key);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定一个key的活动时间,单位:秒(s)
|
||||
*/
|
||||
public function expire($key, $ttl)
|
||||
{
|
||||
$ret = $this->collection->expire($key, $ttl);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回名称为h的hash中元素个数
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return int
|
||||
*/
|
||||
public function hlen ($key)
|
||||
{
|
||||
return $this->collection->hlen($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给key重命名
|
||||
*
|
||||
* @param string $key/存储键名
|
||||
* @return int
|
||||
*/
|
||||
public function rename ($oldkey, $key)
|
||||
{
|
||||
return $this->collection->rename($oldkey, $key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 在子类中(注意注释中填写正确的返回值类型, 一般为类名):
|
||||
* <code>
|
||||
* public static function instance()
|
||||
* {
|
||||
* return parent::_instance(__CLASS__);
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param string $model
|
||||
* @throws Zeed_Exception
|
||||
* @return Zeed_Db_Model_Redis
|
||||
*/
|
||||
protected static function _instance ($model)
|
||||
{
|
||||
if (isset(self::$instanceInternalCache[$model]) &&
|
||||
is_subclass_of(self::$instanceInternalCache[$model], __CLASS__)) {
|
||||
return self::$instanceInternalCache[$model];
|
||||
} elseif (class_exists($model)) {
|
||||
self::$instanceInternalCache[$model] = new $model();
|
||||
return self::$instanceInternalCache[$model];
|
||||
}
|
||||
|
||||
throw new Zeed_Exception('Redis Model( ' . $model . ' ) not exists.');
|
||||
}
|
||||
}
|
||||
|
||||
// End ^ Native EOL ^ UTF-8
|
||||
Reference in New Issue
Block a user