123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Service;
- class RedisService extends RedisInterface
- {
- protected $prefix_fn = 'chat_fn';
- protected $prefix_user = 'chat_user';
- protected $prefix_user_info = 'userListInfo';
- protected $prefix_user_friends = 'myFriends';
- const SERVER_RUN_ID = 'prod';
-
- public function bind(string $fid, int $userId, $run_id = self::SERVER_RUN_ID)
- {
-
- $this->redis->hSet($run_id, $this->prefix_fn . $fid, $userId);
-
- $this->redis->hSet($run_id, $this->prefix_user . $userId, $fid);
- }
-
- public function unbind(string $fid, int $userId, $run_id = self::SERVER_RUN_ID)
- {
- $this->redis->hDel($run_id, $this->prefix_fn . $fid);
- $this->redis->hDel($run_id, $this->prefix_user . $userId);
- }
-
- public function findUser(string $fid, $run_id = self::SERVER_RUN_ID)
- {
- return $this->redis->hGet($run_id, $this->prefix_fn . $fid);
- }
-
- public function findFd(int $userId, $run_id = self::SERVER_RUN_ID)
- {
- return $this->redis->hGet($run_id, $this->prefix_user . $userId);
- }
-
- public function setUserInfo(string $userId, array $data)
- {
- $this->redis->hSet($this->prefix_user_info, $userId, json_encode($data));
- }
-
- public function getUserInfo(string $userId)
- {
- $this->redis->hGet($this->prefix_user_info, $userId);
- }
-
- public function getUserFriends(string $userId)
- {
- return $this->redis->hGet($this->prefix_user_friends, $userId);
- }
-
- public function setUserFriends(string $userId, array $friends)
- {
- $this->redis->hSet($this->prefix_user_friends, $userId, json_encode($friends));
- }
- }
|