redis
代码语言:javascript复制$redis = Yii::$app->redis;
$res = $redis->get('ttp:00d716905c8ed414aa0103ba17815795');
$res = unserialize($res);
return $this->asJson($res);
$redisKey = "yixinzuqiu:houtai:messge:infoMessage:{$id}";
$data = Redis::connection('plan')->get($redisKey);
if ($data){
$data = json_decode($data);
return json_encode(['data' => $data]);
}
Redis::connection('plan')->setex($redisKey, 60, json_encode($info));
复制代码
MSQYL
输出刚刚执行的 SQL
代码语言:javascript复制<?php
use HyperfDbConnectionDb;
use HyperfUtilsArr;
use AppModelBook;
// 启用 SQL 数据记录功能
Db::enableQueryLog();
$book = Book::query()->find(1);
// 打印最后一条 SQL 相关数据
var_dump(Arr::last(Db::getQueryLog()));
复制代码
子查询,原生语句执行
代码语言:javascript复制$changeIndexList = Db::select(' SELECT * FROM (SELECT `id`,`match_id`,`sample_data`,`odds_index`,`type`
FROM `bifen`.`bifen_index_discrete` WHERE `match_id` = ? ORDER BY `id` DESC ) a
GROUP BY `type` ORDER BY `id` DESC,type DESC', [$matchId]);
复制代码
定义空对象
$result = new stdClass();
获取记录某值
代码语言:javascript复制$value->gzh_name = WechatIndex::query()
->where('id', $value->gzh_id)
->value('name');
复制代码
数组idarr
代码语言:javascript复制$userIdArray = StoreUser::query()
->where('is_register', 1)
->pluck('user_id')
->toArray();
$userIdArray = array_unique($userIdArray);
$compensationList = Compensation::query()
->select('id', 'similar') ->whereIn('id', $matchIdArr)
->get()
->toArray();
$midArr = array_unique(array_column($drfinpayzb1List, 'mid'));
$ids = "'" . implode("','", $midArr) . "'";
$drfinpayList = m('drfinpay')->getall("id in (" . $ids . ")", 'id,expensetype');
复制代码