centos7 php redis auth连接被重置

系统centos7.6

php 7.1

php-redis扩展3.1.0

 $this->obj->auth($RedisServer[$key]['password']);

链接重置

<?php

defined('IN_DESTOON') or exit('Access Denied');
class dcache {
	var $pre;
	var $obj;
	
	var $dc_writenum   =   0;
	var $dc_rednum     =   0;
	var $dc_redtime    =   0;
	var $dc_writetime  =   0;
	var $dcinfo        =   '';
	var $debug         =   0;

    function __construct() {
		$this->obj = new Redis;
		include DT_ROOT.'/file/config/redis.inc.php';
		$num = count($RedisServer);
		$key = $num == 1 ? 0 : abs(crc32($GLOBALS['DT_IP']))%$num;
		$r = $this->obj->pconnect($RedisServer[$key]['host'], $RedisServer[$key]['port']);
        if ($RedisServer[$key]['persistent']) {
            $this->obj->pconnect($RedisServer[$key]['host'], $RedisServer[$key]['port'], $RedisServer[$key]['timeout'], 'persistent_id_' . $RedisServer[$key]['select']);
        } else {
            $this->obj->connect($RedisServer[$key]['host'], $RedisServer[$key]['port'], $RedisServer[$key]['timeout']);
        }
        
        if ('' != $RedisServer[$key]['password']) {
            $this->obj->auth($RedisServer[$key]['password']);
        }
        
        if (0 != $RedisServer[$key]['select']) {
            $this->obj->select($RedisServer[$key]['select']);
        }
		if($r===false) exit('redis connect error');
    }

    function dcache() {
		$this->__construct();
    }

	function get($key) {
	    global $bugconfig;
	    if($this->debug) $temp1 = microtime(true);//
	    $val = $this->obj->get($this->pre.$key);
	    if(substr($val, 0, 2) == 'a:') {
	        $arr = unserialize($val);
	        if(is_array($arr)) {
	            if($this->debug) {
	                $temp2 = microtime(true);$subtime = $temp2-$temp1;$this->dc_redtime +=$subtime ;$this->dc_rednum++;
	                $style = "style='color:#ccc'";
	                if($subtime*1000>(isset($bugconfig['max_execute_time'])?intval($$bugconfig['max_execute_time']):5)){
	                    $style = "style='color:#F00'";
	                }
	                $this->dcinfo .= "<p ".$style.">R-".$this->dc_rednum."【".$key.':'.number_format($subtime*1000,0)."ms】</p>\n";//
	            }
	            return $arr;
	        }
	    }
	    if($this->debug) {
	        $temp2 = microtime(true);$subtime = $temp2-$temp1;$this->dc_redtime +=$subtime ;$this->dc_rednum++;
	        $style = "style='color:#ccc'";
	        if($subtime*1000>(isset($bugconfig['max_execute_time'])?intval($$bugconfig['max_execute_time']):5)){
	            $style = "style='color:#F00'";
	        }
	        $this->dcinfo .= "<p ".$style.">R-".$this->dc_rednum."【".$key.':'.number_format($subtime*1000,0)."ms】</p>\n";//
	    }
	    return $val;
    }

    function set($key, $val, $ttl = 600) {
        global $bugconfig;
        if($this->debug) $temp1 = microtime(true);
        if(is_array($val)) $val = serialize($val);
        $result = $ttl ? $this->obj->setex($this->pre.$key, $ttl, $val) : $this->obj->set($this->pre.$key, $val);
        if($this->debug) {
            $style = "style='color:#ccc'";
            $temp2 = microtime(true);$subtime = $temp2-$temp1;$this->dc_writetime +=$subtime ;$this->dc_writenum++;
            if($subtime*1000>(isset($bugconfig['max_execute_time'])?intval($$bugconfig['max_execute_time']):5)){
                $style = "style='color:#F00'";
            }
            $this->dcinfo .= "<p ".$style.">W-".$this->dc_writenum."【".$key.':'.number_format($subtime*1000,0)."ms】</p>\n";//
        }
        return $result;
    }

    function rm($key) {
		return $this->obj->delete($this->pre.$key);
    }

    function clear() {
        return $this->obj->flushAll();
    }

	function expire() {
		return true;
	}
	/**
	 * 设置失效时间
	 * @return bool true false
	 */
	function setexpire($key, $ttl=5) {
	    return $this->obj->expire($this->pre.$key, $ttl);
	}
	
	/**
	 * 当 key 不存在时,返回 -2 。 当 key存在但没有设置剩余生存时间时,返回 -1 。 否则,以秒为单位,返回 key 的剩余生存时间。
	 注意:在 Redis 2.8以前,当 key不存在或者 key没有设置剩余生存时间时,命令都返回 -1 。
	 */
	function ttl($key) {
	    return $this->obj->ttl($this->pre.$key);
	}
	
	function setnx($key, $val) {
	    return $this->obj->setnx($this->pre.$key, $val);
	}

    /**
     * 从所有db中按通佩符删除所有数据库中匹配的缓存
     * @param  [type] $keypartern [description]
     * @return [type]             [description]
     */
    function rmbypartern($keypartern){
        $r=0;
        $keys = $this->obj->keys($this->pre.$keypartern);
        foreach ($keys as $key => $value) {
            $r++;
            $this->obj->delete($value);
        }
        return $r;
    }
}
?>

解决办法:

升级php-redis扩展,下载地址:

http://pecl.php.net/package/redis

http://pecl.php.net/get/redis-4.2.0.tgz

 

命令:

wget http://pecl.php.net/get/redis-4.2.0.tgz

tag -zxvf redis-4.2.0.tgz

 cd redis-4.2.0.tgz

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

extension=/usr/local/php/lib/php/extensions/no-debug-zts-20160303/redis.so

 

重启apache

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值