1. In Postman, POST to http://api.pcs-api.localhost/v1/mobile/rtcs/invite-accept, and write the data from the Body into the Redis cache as an array, as shown in Figure 1.

2. With each request, the data in the Body changes. The implementation logic in the program is as follows:
RTC 邀请接受通话:/mobile/rtcs/invite-accept ( mobile/rtc/invite-accept )
1、请求参数列表
( 1 ) user_name:必填,用户名称
( 2 ) call_mode:必填,通话方式,voice_call:语音通话;video_call:视频通话
2、输入数据验证规则
( 1 ) 必填:user_name、call_mode
( 2 ) 字符串:user_name、call_mode
( 3 ) 范围([voice_call, video_call]):call_mode
( 4 ) 判断房间是否存在,是:响应失败
3、操作数据
( 1 ) 设置RTC 邀请接受通话数据的缓存键
( 2 ) 从缓存中取回RTC 邀请接受通话数据
A、如果不存在,则序列化,将RTC 邀请接受通话数据存放到缓存供下次使用,在缓存中永久保留
B、如果存在,则反序列化,带索引检查计算数组的差集,如果差集不为空,将RTC 邀请接受通话数据存放到缓存供下次使用,在缓存中永久保留
3. Compute the difference of arrays with an index check to compare whether the arrays are equal. Since the data in the Body has undergone strict validation, it is guaranteed that the data in the Body will only be less than or equal to the data in the cache. The code implementation is as follows:
// 设置RTC 邀请接受通话数据的缓存键
$redisCache = Yii::$app->redisCache;
$gisRtcInviteAcceptCacheKey = implode(':', ['gis', 'rtc', 'invite', 'accept', $identity->group_id]);
// 从缓存中取回RTC 邀请接受通话数据
$gisRtcInviteAcceptCacheData = $redisCache[$gisRtcInviteAcceptCacheKey];
$requestGisRtcInviteAccept = [
'user_name' => $user_name,
'call_mode' => $call_mode,
];
if ($gisRtcInviteAcceptCacheData === false) {
// 将RTC 邀请接受通话数据存放到缓存供下次使用,在缓存中永久保留
$redisCache->set($gisRtcInviteAcceptCacheKey, serialize($requestGisRtcInviteAccept));
} else {
$gisRtcInviteAccept = unserialize($gisRtcInviteAcceptCacheData);
// 带索引检查计算数组的差集
$result = array_diff_assoc($gisRtcInviteAccept, $requestGisRtcInviteAccept);
if (!empty($result)) {
// 将RTC 邀请接受通话数据存放到缓存供下次使用,在缓存中永久保留
$redisCache->set($gisRtcInviteAcceptCacheKey, serialize($requestGisRtcInviteAccept));
}
}4. array_diff_assoc() returns an array containing all the values from array1 that are not present in any of the other argument arrays. Note that, unlike array_diff(), the keys are also used in the comparison. Print the array from the cache, the request data from the Body, and the computed array difference with the index check, respectively. The results match expectations. The cache data is overwritten only when the computed array difference with the index check is not empty.
$gisRtcInviteAccept
Array
(
[user_name] => huaqiyun
[call_mode] => voice_call
)
{
"user_name": "huaqiyun1",
"call_mode": "voice_call"
}
array(1) {
["user_name"]=>
string(8) "huaqiyun"
}
$gisRtcInviteAccept
Array
(
[user_name] => huaqiyun
[call_mode] => voice_call
)
{
"user_name": "huaqiyun",
"call_mode": "video_call"
}
array(1) {
["call_mode"]=>
string(10) "voice_call"
}
$gisRtcInviteAccept
Array
(
[user_name] => huaqiyun
[call_mode] => voice_call
)
{
"user_name": "huaqiyun2",
"call_mode": "video_call"
}
array(2) {
["user_name"]=>
string(8) "huaqiyun"
["call_mode"]=>
string(10) "voice_call"
}
