phalcon 连接redis 请求解答

之前使用phalcon+memcached,memcached的类是自己写的类加载进来,目前使用正常。但是想尝试下使用redis,但是连接却提示 redis server went away 。phalcon无法连接到服务器的redis,想看看各位能不能有一个提示或者代码的例子可以参考。

我是这样写的
Redis.php

class Redis  {
protected $redis = null;

    public function __construct(){
        $this->redis = $this->_initMemcache();
    }

    protected function _initMemcache(){
        
        $redis = new redis();
        $redis->connect("ip地址","63796");
        return $redis;
    }
}
阅读 6.8k
7 个回答

redis服务器挂了. 要么你没启动, 要么地址写错了.

redis的默认端口是6379不是63796

用命令行连接Redis服务器看看

新手上路,请多包涵

phalcon 自带的 redis 实现,因为是兼容 memcache, 所以只支持 简单的 string 操作。 如果只想用 redis,最好不要用自带的 redis 类

是不是因为redis 默认127.0.0.1 外网访问不了

报这个错,一看就是你那个redis服务器没开啊

在保证redis服务正常启动,可以这样连接:

public function __construct()
{
    $redis = new \Redis();
    $this->port = 6379;
    $this->host = '127.0.0.1';
    $redis->connect($this->host, $this->port);
    $this->redis = $redis;
    // $this->auth = $config['auth'];
    $this->expireTime = time() + 30;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题