Workerman onWorkerStart initialization redis connection question

this question encountered when using workerman"s gateway framework
Events.php

<?php
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

/**
 * 
 * declare//php start.php reload
 * workerman.logprocess_timeout
 */
//declare(ticks=1);

use \GatewayWorker\Lib\Gateway;
use Workerman\Lib\Timer;
use \Server\Common;
use \Server\Cmd;
/**
 * 
 *  onConnect onMessage onClose 
 * onConnect  onClose 
 */
class Events
{
    public static $redisCon = null ;
    /**
     * 
     * onConnect
     * 
     * @param int $client_id id
     */
    public static function onConnect($client_id  ) {
        
    }
   /**
    * 
    * @param int $client_id id
    * @param mixed $message 
    */
   public static function onMessage($client_id, $message) {
      
   }
   public static function onWorkerStart($businessWorker){
        self::initRedis();
   }
   /**
    * 
    * @param int $client_id id
    */
   public static function onClose($client_id) {
        echo "client_id is $client_id is close \n";
   }
   //redis
   public static function  initRedis(){
        $redisConfig = require_once __DIR__ . "/Server/Config/Redis.config.php";
        self::$redisCon = Server\Library\RedisDB::getInstance( $redisConfig , 0  );
   }
}

RedisDB.php

<?php
namespace Server\Library ;
class RedisDB
{
    static $_instance; //
    public $handler;
    private $config = null ;
    public function __construct($redisConfig , $dbindex = 0){
        if (!extension_loaded("redis")) {
            throw new Exception("REDIS NOT  SUPPORT", 1);
        }
        $this->handler = new \Redis();
        //
        $this->handler->pconnect($redisConfig["hostname"], $redisConfig["port"]);
        $this->handler->auth($redisConfig["auth"]);
    }

    public static function getInstance($redisConfig , $index = 0)
    {
        if (!isset(self::$_instance[$index]) or FALSE == (self::$_instance[$index] instanceof self)) {
            self::$_instance[$index] = new self($redisConfig , $index);
        }
        return self::$_instance[$index];
    }  
}

start_businessworker.php
I opened

$worker->count = 8;

question:

redisnew redis8
id=1017 addr=192.168.2.188:56012 fd=9 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1018 addr=192.168.2.188:56013 fd=10 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1019 addr=192.168.2.188:56016 fd=11 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1020 addr=192.168.2.188:56025 fd=12 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1021 addr=192.168.2.188:56024 fd=13 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1022 addr=192.168.2.188:56028 fd=14 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1023 addr=192.168.2.188:56038 fd=15 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth
id=1024 addr=192.168.2.188:56039 fd=16 name= age=659 idle=659 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth

but I just assigned a static variable to a class after initializing the connection above. In that case, isn"t there only one connection?
is it based on worker"s id?
Please advise

< hr >

above I use singleton mode for redis connection!

Mar.22,2021

this video of the actual combat project between workerman and thinkPHP is good. It uses websocket protocol to achieve a long connection to do instant messaging and online customer service. Address http://study.163.com/course/i.

Menu