【发布时间】:2020-06-25 05:06:24
【问题描述】:
我在 Redis 缓存中有一个这样的数组
127.0.0.1:6379> MGET laravel:campaign1107
1) "a:1:{s:21:\"unsubscriberCount1107\";i:2;}"
127.0.0.1:6379>
现在我需要获取unsubscriber1107 值。我试过这样
dd(cache()->get($arrayCacheKey[$cacheKey]));
但是,它不起作用。如何访问此对象?
我的设置缓存代码
public function updateUnsubscriberCountCache($campaign_id, $type)
{
$assoc = [];
$arrayCacheKey = 'campaign'.$campaign_id.'';
$cacheKey = 'unsubscriberCount'.$campaign_id.'';
if($type == 'unsubscriberLogCount') {
$cacheKey = 'unsubscriberCount'.$campaign_id.'';
if( cache()->get($cacheKey) > 0) {
cache()->increment($cacheKey);
//cache()->forget($cacheKey);
} else {
$total = UnsubscribeLog::select('unsubscribe_logs.*')->leftJoin('tracking_logs', 'tracking_logs.message_id', '=', 'unsubscribe_logs.message_id')->where('tracking_logs.campaign_id', '=', $campaign_id)->distinct('subscriber_id')->count('subscriber_id');
//cache()->forever($cacheKey, $total);
$assoc[$cacheKey] = $total;
cache()->forever($arrayCacheKey, $assoc);
}
}
}
【问题讨论】:
-
你是如何设置值的?
-
编辑我的问题。请检查