use Illuminate\Support\Facades\Redis;
// ...
public static function getByIdWithCache($id) {
Redis::select(6);
$key = sprintf("CarV2:MERCHANT:%d", $id);
$columns = array( "id", "merchant_type_id","member_username","company_full_name",
"city_code","recommend_id","name");
$values = Redis::hMget($key, $columns);
if (!empty($values[0])) {
$mch = new Merchants();
for ($i = 0, $n = count($values); $i < $n; $i++) {
$mch->setAttribute($columns[$i], $values[$i]);
}
return $mch;
}
/** @var $mch Merchants */
$mch = self::where("id", "=", $id)->get($columns)->first();
if (empty($mch)) {
Redis::hSet($key, "id", 0);
return $mch;
}
foreach ($columns as $c) {
Redis::hSet($key, $c, $mch->getAttribute($c));
}
Redis::expire($key, 3600);
return $mch;
}
Redis hmset, hmget
原创
©著作权归作者所有:来自51CTO博客作者mzh9112的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Mbstring.php
下一篇:SnowFlake.php
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
redis hmget和hget redis hmget和hgetall性能差别
1、SQL与NOSQL的区别 1.1 SQL 1.1.1 特点 行存储,二维 结构化&nbs
redis hmget和hget Lua redis 数据结构