php hyperf 读取redis,存储到数据库
2023-12-18 17:52:34
redis中排行榜中的数据
public function execute(string $date)
{
$query = ChannelConfig::query();
$query->where('module_name', 'rank_reward');
$rewardData = $query->first();
$rewards = [];
if( $rewardData ){
$rewardContents = $rewardData->content;
foreach ($rewardContents as $key => $value) {
if( !key_exists($value["game_type"], $rewards) ){
$rewards[$value["game_type"]] = [];
}
$rewards[$value["game_type"]][$value["rank"]] = $value["reward"];
}
}
echo json_encode($rewards);
$redisFactory = ApplicationContext::getContainer()->get(RedisFactory::class);
$redis = $redisFactory->get('rank');
$day = substr($date,5,2).substr($date,8,2);
$keys = $redis->keys("RANK:*:$day:0-0");
foreach ($keys as $key => $value) {
// echo "key = $value \n";
$kuCuns = $redis->ZREVRANGE($value, 0, 29, true);
// echo "data = ".json_encode($kuCuns)."\n";
$gameType = explode(":",$value)[1];
$count = count($kuCuns);
$index = 1;
foreach ($kuCuns as $keyItem => $valueItem) {
$mode = new RankLog();
$mode->date = $date;
$mode->index = $index;
$mode->gameType = $gameType;
$mode->userId = $keyItem;
$mode->score = $valueItem;
$mode->reward = key_exists($gameType, $rewards) ? $rewards[$gameType][$index] : "";
$mode->save();
$index++;
}
}
}
文章来源:https://blog.csdn.net/wwj256/article/details/135065961
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!