|
@@ -11,7 +11,8 @@ class CacheRedis extends Cache
|
|
|
private $connected;
|
|
|
private $type;
|
|
|
private $prefix;
|
|
|
- public function __construct() {
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
$this->config = C('redis');
|
|
|
if (empty($this->config['slave'])) $this->config['slave'] = $this->config['master'];
|
|
|
$this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6).'_';
|
|
@@ -30,7 +31,6 @@ class CacheRedis extends Cache
|
|
|
$this->handler = new Redis;
|
|
|
$this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
|
|
|
$_cache = $this->handler;
|
|
|
-// $_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -43,7 +43,6 @@ class CacheRedis extends Cache
|
|
|
$this->handler = new Redis;
|
|
|
$this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
|
|
|
$_cache = $this->handler;
|
|
|
-// $_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -67,7 +66,6 @@ class CacheRedis extends Cache
|
|
|
$this->type = $prefix;
|
|
|
|
|
|
$value = serialize($value);
|
|
|
-
|
|
|
if(is_int($expire)) {
|
|
|
$result = $this->handler->setex($this->_key($key), $expire, $value);
|
|
|
}else{
|
|
@@ -76,6 +74,40 @@ class CacheRedis extends Cache
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ public function set_org($key,$val,$prefix = '')
|
|
|
+ {
|
|
|
+ $this->init_master();
|
|
|
+ if (!$this->enable) return false;
|
|
|
+ $this->type = $prefix;
|
|
|
+ $result = $this->handler->set($this->_key($key), $val);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function incr($key,$prefix = '')
|
|
|
+ {
|
|
|
+ $this->init_master();
|
|
|
+ if (!$this->enable) return false;
|
|
|
+ $this->type = $prefix;
|
|
|
+ $key = $this->_key($key);
|
|
|
+ $value = $this->handler->incr($key);
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function incrby($key,$val,$prefix = '') {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function decr($key,$prefix)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function decrby($key,$val,$prefix = '')
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public function zIncrBy($key, $value, $member,$prefix='')
|
|
|
{
|
|
|
$this->init_master();
|
|
@@ -96,7 +128,8 @@ class CacheRedis extends Cache
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- public function hset($name, $prefix, $data) {
|
|
|
+ public function hset($name, $prefix, $data)
|
|
|
+ {
|
|
|
$this->init_master();
|
|
|
if (!$this->enable || !is_array($data) || empty($data)) return false;
|
|
|
$this->type = $prefix;
|
|
@@ -141,15 +174,13 @@ class CacheRedis extends Cache
|
|
|
} else {
|
|
|
return $this->handler->del($this->_key($name));
|
|
|
}
|
|
|
- } else {
|
|
|
- if (is_array($name)) {
|
|
|
- foreach ($name as $key => $value) {
|
|
|
- $this->handler->hdel($this->_key($name), $key);
|
|
|
- }
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return $this->handler->hdel($this->_key($name), $key);
|
|
|
+ } elseif (is_array($name)) {
|
|
|
+ foreach ($name as $key => $value) {
|
|
|
+ $this->handler->hdel($this->_key($name), $key);
|
|
|
}
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return $this->handler->hdel($this->_key($name), $key);
|
|
|
}
|
|
|
}
|
|
|
|