hyperf-chat/app/Cache/SocketRoom.php

77 lines
1.4 KiB
PHP
Raw Normal View History

2021-05-21 22:56:42 +08:00
<?php
namespace App\Cache;
use App\Cache\Repository\SetGroupRedis;
2021-07-29 23:30:42 +08:00
use App\Traits\StaticInstance;
2021-05-21 22:56:42 +08:00
2021-05-22 20:54:30 +08:00
/**
* 聊天室 - 缓存助手
*
* @package App\Cache
*/
2021-05-21 22:56:42 +08:00
class SocketRoom extends SetGroupRedis
{
2021-07-29 23:30:42 +08:00
use StaticInstance;
2021-05-21 22:56:42 +08:00
protected $name = 'ws:room';
/**
* 获取房间名
*
* @param string|integer $room 房间名
* @return string
*/
public function getRoomName($room)
{
return $this->getCacheKey($room);
}
/**
* 获取房间中所有的用户ID
*
* @param string $room 房间名
* @return array
*/
public function getRoomMembers(string $room)
{
return $this->all($room);
}
/**
* 添加房间成员
*
* @param string $room 房间名
* @param string ...$member 用户ID
* @return bool|int
*/
public function addRoomMember(string $room, string ...$member)
{
return $this->add($room, ...$member);
}
2021-08-20 22:38:46 +08:00
/**
*
* 删除房间成员
*
* @param string $room 房间名
* @param string ...$member 用户ID
* @return int
*/
public function delRoomMember(string $room, string ...$member): int
2021-05-21 22:56:42 +08:00
{
return $this->rem($room, ...$member);
}
/**
* 删除房间
*
* @param string|int $room 房间名
* @return int
*/
2021-08-20 22:38:46 +08:00
public function delRoom($room): int
2021-05-21 22:56:42 +08:00
{
return $this->delete($room);
}
}