-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
当前 Manager::findManyFromCache() 的实现中,虽然使用 getMultiple() 批量读取缓存,但在写入缓存时采用了逐个 set()的方式,redis往返开销成为性能瓶颈。
// 当前实现 (Manager.php)
foreach ($targetIds as $id) {
$key = $this->getCacheKey($id, $instance, $handler->getConfig());
if ($model = $dictionary[$id] ?? null) {
$handler->set($key, $this->formatModel($model), $ttl); // N 次独立的 Redis 操作
}
}测试数据(15个用户模型,无缓存情况):
当前实现:数据库查询1.5ms,缓存写入耗时 9.59ms
使用 Pipeline 优化后:缓存写入耗时 1.16ms
Describe the solution you'd like
// 建议的实现
$pipeline = $redis->pipeline();
foreach ($targetIds as $id) {
$key = $this->getCacheKey($id, $instance, $handler->getConfig());
if ($model = $dictionary[$id] ?? null) {
$data = array_merge(['HF-DATA' => 'DEFAULT'], $this->formatModel($model));
$pipeline->hMSet($key, $data);
if ($ttl > 0) {
$pipeline->expire($key, $ttl);
}
}
}
$pipeline->exec();Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request