hyperf-chat/app/Cache/FriendRemarkCache.php

38 lines
803 B
PHP
Raw Normal View History

2020-11-09 22:59:25 +08:00
<?php
namespace App\Cache;
/**
* Class FriendRemarkCache
2021-04-20 16:30:57 +08:00
*
2020-11-09 22:59:25 +08:00
* @package App\Cache
*/
class FriendRemarkCache
{
const KEY = 'hash:user:friend:remark:cache';
/**
* 设置好友备注缓存
*
2021-04-20 16:30:57 +08:00
* @param int $user_id 用户ID
* @param int $friend_id 好友ID
* @param string $remark 好友备注
2020-11-09 22:59:25 +08:00
*/
public static function set(int $user_id, int $friend_id, string $remark)
{
redis()->hset(self::KEY, "{$user_id}_{$friend_id}", $remark);
}
/**
* 获取好友备注
*
2021-04-20 16:30:57 +08:00
* @param int $user_id 用户ID
2020-11-09 22:59:25 +08:00
* @param int $friend_id 好友ID
* @return string
*/
public static function get(int $user_id, int $friend_id)
{
return redis()->hget(self::KEY, "{$user_id}_{$friend_id}") ?: '';
}
}