改进redisd驱动

This commit is contained in:
thinkphp
2016-05-05 16:40:02 +08:00
parent c22b26026e
commit a134da6563

View File

@@ -131,7 +131,7 @@ class Redisd
$this->handler->$func($host, $port, $this->options['timeout']);
if ($this->options ['password'] != null) {
if (null != $this->options['password']) {
$this->handler->auth($this->options['password']);
}
@@ -165,12 +165,13 @@ class Redisd
//$this->handler->slaveof();
} else {
//尝试failover如果有其它节点则进行其它节点的尝试
foreach ($this->options["server_slave"] as $k=>$v)
{
if (trim($v) == trim($host))
foreach ($this->options["server_slave"] as $k => $v) {
if (trim($v) == trim($host)) {
unset($this->options["server_slave"][$k]);
}
}
//如果无可用节点,则抛出异常
if (!count($this->options["server_slave"])) {
Log::record("已无可用Redis读节点", Log::ERROR);
@@ -197,8 +198,6 @@ class Redisd
*/
public function get($name)
{
Cache::$readTimes++;
$this->master(false);
try {
@@ -217,7 +216,7 @@ class Redisd
$jsonData = $value ? json_decode($value, true) : $value;
}
return ($jsonData === NULL) ? $value : $jsonData;
return (null === $jsonData) ? $value : $jsonData;
}
/**
@@ -231,8 +230,6 @@ class Redisd
*/
public function set($name, $value, $expire = null)
{
Cache::$writeTimes++;
$this->master(true);
if (is_null($expire)) {
@@ -247,7 +244,7 @@ class Redisd
*/
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
if ($value === null) {
if (null === $value) {
return $this->handler->delete($this->options['prefix'] . $name);
}
@@ -276,7 +273,7 @@ class Redisd
* @access public
* @return object
*/
function handler()
public function handler()
{
return $this->handler;
}
@@ -290,7 +287,6 @@ class Redisd
*/
public function rm($name)
{
Cache::$writeTimes++;
$this->master(true);
return $this->handler->delete($this->options['prefix'] . $name);
}
@@ -303,8 +299,6 @@ class Redisd
*/
public function clear()
{
Cache::$writeTimes++;
$this->master(true);
return $this->handler->flushDB();
}
@@ -321,8 +315,10 @@ class Redisd
//如果代码中使用pconnect close的作用仅是使当前php不能再进行redis请求但无法真正关闭redis长连接连接在后续请求中仍然会被重用直至fpm进程生命周期结束。
try {
if(method_exists($this->handler, "close"))
if (method_exists($this->handler, "close")) {
$this->handler->close();
}
} catch (\Exception $e) {
}
}