我有两种方法,一种是查询数据库,另一种是从Redis缓存中检索数据。
public function aaa()
{
for ($i = 0; $i < 1000; $i++) {
$gl = DB::connection('webhesab')->table('gl_trans')
->where('memo_','LIKE','%شعبه%')
->orWhere('account','=',111001)
->where('dimension2_id','<>',1)
->orWhere('person_id',0)
->where('dimension2_id',1)
->orWhere('type_no',50)
->limit(10)
->get();
}
}
public function bbb()
{
for ($i = 0; $i < 1000; $i++) {
$gl = cache()->get('gl_trans');
}
}
缓存对象的值与查询值完全相同。
但是缓存比数据库查询慢得多。 aaa
大约300毫秒,而bbb
大约1900毫秒。
为什么?有什么问题吗?