Oskar Persson
Oskar Persson

Reputation: 6765

Using PHP, MySQL and Redis

I'm trying to understand how to cache databases in a good way and what to do and what not to do. Though I want to make sure that I've understood everything correctly so far. Maybe you can help me?

At the moment I don't have any caching and I do everything locally using XAMPP. For storing data I use MySQL/PHPMyAdmin and to grab, add and update data I simply make Mysqli queries in PHP. As I said, I don't have any caching as of now, so I started looking for the best ways to do it.

After a quick search I found Redis. So my idea is to store data using MySQL and cache it with Redis. Is this a good way to do it or have I understood everything completely wrong?

If I'm right, how do I implement Redis? How do I cache data? Do I make a check in PHP if the data I want is cached, if it is then take it from the cache, else take it from the MySQL database.

Would really like to know if I'm on the right track.

Upvotes: 6

Views: 9275

Answers (1)

Aravind.HU
Aravind.HU

Reputation: 9472

Redis is an open source data structure server with an in-memory dataset that does much more than simple key/value storage thanks to its built-in data types.

If your requirement is to cache bulk data, you can go for it and here is a quick tutor for it

If you just want to achieve caching you can use memcache

memcache is good for storing slow queries that return small data sets [1 - 50 results, depending on the average row weight]

memcache is not so efficient for any query that returns large data sets [100 - ∞, depending on the average row weight]

Here are some of the links where you can find more info on memcache

Memcache introduction

using memcache with php and mysql

and also, last but not least

Mysql also caches results of queries, may be you can increase mysql query cache size? Or cache the result of big query in a standalone table.

More information on Mysql query caching is provided in many of the SO postings but the best one I felt to present is the one here

Mysql query caching

The above SO posting may help you out

Upvotes: 11

Related Questions