Using Redis as Laravel Cache is not improving performance #47389
Unanswered
jonaspauleta
asked this question in
Q&A
Replies: 1 comment
-
Is Redis on the same server as PHP? Are you using localhost for the IP address? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have setted up Laravel to use Redis as cache driver.
But when I try to Cache something through Cache Facade I see no response time improvement, speaking on getting 2000 database records, from the table Posts where it has an ID, Title, Description and Timestamps, thus, taking about 500ms to retrive the data. However, when using the Redis Facade, the request times got down to about an half, to arround 250ms.
See the code examples below:
So, this way, I am getting the response in 250ms
if ($posts = Redis::get('posts.all')) {
return json_decode($posts);
}
$posts = Post::all();
Redis::set('posts.all', json_encode($posts));
return $posts;
But this way it takes 500ms
return Cache::remember('posts', 33600, function () {
return Post::all();
});
It takes also 500ms when I do this way
return Post::all();
I have just checked if Laravel was still using file as cache driver by taking a look at the folder storage/framework/cache/ and it has nothing on the posts I am Cache, then I checked Redis and when I used the Cache Facade it goes to Redis DB 1, and when I use the Redis Facade it goes to Redis DB 0
Any thoughts why using Redis as Cache have no performance gains?
Beta Was this translation helpful? Give feedback.
All reactions