Using PHP, MySQL and Redis

I am trying to understand how to cache databases efficiently and what to do and what not to do. Although I want to make sure that I understood correctly. Maybe you can help me?

At the moment, I do not have caching, and I do everything locally using XAMPP. For data storage, I use MySQL / PHPMyAdmin, and for capturing, adding and updating data, I just make Mysqli queries in PHP. As I said, at the moment I do not have caching, so I started looking for the best ways to do this.

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

If I am right, how do I implement Redis? How to cache data? I am doing a PHP check if the data I want is cached, if they then take it from the cache and then take it from the MySQL database.

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

+4
source share
1 answer

Redis is an open source data structure server with a dataset in memory that does much more than just store keys and values ​​with embedded data.

If you need 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 [results from 1 to 50, depending on average row weight]

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

Here are some of the links where you can find more information about memcache

Memcache Introduction

using memcache with php and mysql

and finally, at least

Mysql also caches query results, maybe you can increase the size of the mysql query cache? Or cache the result of a large query in a separate table.

More info on Mysql query caching is provided in many SO posts, but the best I felt like submitting is here

mysql query caching

The above SO post may help you

+9
source

Source: https://habr.com/ru/post/1437639/


All Articles