__handlePropertyHandler(__CLASS__); } protected $prefix_fn = 'chat_fn'; protected $prefix_user = 'chat_user'; /** * 绑定fd和用户关系 * @param string $fid * @param int $userId * @param $run_id * @return void * @throws \RedisException */ public function bind(string $fid, int $userId, $run_id = SERVER_RUN_ID) { //站点通道+用户 $this->redis->hSet($run_id, $this->prefix_fn . $fid, $userId); //站点用户+通道 $this->redis->hSet($run_id, $this->prefix_user . $userId, $fid); } /** * 解绑通道和用户关系 * @param string $fid * @param int $userId * @param $run_id * @return void * @throws \RedisException */ public function unbind(string $fid, int $userId, $run_id = SERVER_RUN_ID) { $this->redis->hDel($run_id, $this->prefix_fn . $fid); $this->redis->hDel($run_id, $this->prefix_user . $userId); } /** * 通过FD获取userID * @param string $fid * @param $run_id * @return false|\Redis|string * @throws \RedisException */ public function findUser(string $fid, $run_id = SERVER_RUN_ID) { return $this->redis->hGet($run_id, $this->prefix_fn . $fid); } /** * 通过UserID 获取fd * @param int $userId * @param $run_id * @return false|\Redis|string * @throws \RedisException */ public function findFd(int $userId, $run_id = SERVER_RUN_ID) { return $this->redis->hGet($run_id, $this->prefix_user . $userId); } }