PHP

搭配ccORM的redis连接操作类代码

字号+ 编辑: 国内TP粉 修订: 听风就是我 来源: 原创 2023-09-11 我要说两句(0)

搭配orm的Redis操作库代码。需要搭配Yaf框架。

Redis连接类代码, 注意, 本代码是阻塞的,需要搭配Yaf配置文件。

class Redis_Worker
    {
        /**
         * 业务逻辑用长连接线程
         * @var  array
         */
        private static $_redisp = [];
 
        /**
         * 启动连接
         * @access  public   static
         * @param   integer  $dbIndex
         * @return  object
         */
        public static function connect(int $dbIndex = 0)
        {
            $redis = new \Redis();
            $config = Yaf\Registry::get('config')->redis;
            $redis->connect($config->host, (int) $config->port);
            $redis->auth($config->auth);
            $redis->select($dbIndex);
            return $redis;
        }
 
        /**
         * 长连接句柄
         * 根据库序号产生多个句柄容器
         * @access  public
         * @param   integer  $dbIndex  库号
         * @return  object
         */
        public static function pconnect(int $dbIndex = 0)
        {
            if (!isset(self::$_redisp[$dbIndex])) {
                self::$_redisp[$dbIndex] = new \Redis();
            }
            $redis = &self::$_redisp[$dbIndex];
            $config = Yaf\Registry::get('config')->redis;
            $redis->pconnect($config->host, (int) $config->port);
            $redis->auth($config->auth);
            $redis->select($dbIndex);
            return self::$_redisp[$dbIndex];
        }
    }

为什么不封装其他数据操作方法?

简直多余。不想浪费别人脑细胞,phpredis库本身已经封装的很好了, 还封装个屁啊。。。

阅完此文,您的感想如何?
  • 有用

    0

  • 没用

    0

  • 开心

    0

  • 愤怒

    0

  • 可怜

    0

1.如文章侵犯了您的版权,请发邮件通知本站,该文章将在24小时内删除;
2.本站标注原创的文章,转发时烦请注明来源;
3.交流群: PHP+JS聊天群

相关课文
  • mac开发接入微信公众号接口返回报错 cURL error 56: SSLRead() return error -9806

  • pecl安装程序时报错Array and string offset access syntax with curly braces is no longer supported

  • PHP的换行符是什么

  • 由于商家传入的H5交易参数有误,该笔交易暂时无法完成,请联系商家解决

我要说说
网上宾友点评
沙发已空