예제 #1
0
 function onPacket($serv, $data, $addr)
 {
     $req = unserialize($data);
     //错误的请求
     if (empty($req['cmd'])) {
         return;
     }
     $ipAddress = $addr['address'];
     //没有建立映射
     if (empty($this->ipMap[$ipAddress])) {
         //建立映射
         if ($req['cmd'] == 'putInfo' and !empty($req['info'])) {
             $nodeInfo = new NodeInfo();
             $nodeInfo->setInfo($req['info']);
             $nodeInfo->address = $ipAddress;
             $nodeInfo->port = $addr['port'];
             $this->ipMap[$ipAddress] = $nodeInfo;
             $this->log("new node, address={$ipAddress}, version=" . $nodeInfo->version);
             //存储hostname
             $this->redis->sAdd(self::KEY_NODE_LIST, $nodeInfo->hostname);
         } else {
             $this->serv->sendto($addr['address'], $addr['port'], serialize(['cmd' => 'getInfo']));
             //存储Socket用于强制升级
             $this->redis->hSet(self::KEY_NODE_SOCKET, $addr['address'], $addr['port']);
         }
     } else {
         $nodeInfo = $this->ipMap[$ipAddress];
         call_user_func([$this, '_udp_' . $req['cmd']], $nodeInfo, $req);
     }
 }
예제 #2
0
파일: Redis.php 프로젝트: pan269/php-webim
 function login($client_id, $info)
 {
     $this->redis->set(self::$prefix . 'client_' . $client_id, serialize($info));
     $this->redis->sAdd(self::$prefix . 'online', $client_id);
 }
예제 #3
0
 function login($client_id)
 {
     $this->redis->sAdd(self::$prefix . 'online', $client_id);
 }