Article Directory
In this article, we want to explain is how to use redis, do mysql cache.
The actual production environment, the client database read operation is to take data directly to redis redis cache if there is no data, they will go to get mysql data, and cache data in a redis redis to have two case can not be used: expired data or data in mysql updated when users read access redis, when users write access mysql. Actually read demand is great, redis happens to be among the data cached in memory, the response speed is fast, can also reduce the pressure on our back-end database mysql
Experimental background:
server1 nginx php 172.25.2.10
server2 数据库redis 172.25.2.11
真机 msql(mariadb数据库) 172.25.2.250
关闭3台主机的防火墙和selinux
Basic environment to build
1. The process redis on the original server1 are closed.
2. Configure nginx webserver do
2. Edit the nginx configuration file
Open nginx
Php installed on server1
Written test page on server1:
Allows users to access data when the first went to redis modules take data, if there is no data or data module redis has expired, the user will find mysql to get data
2. Install redis on server2
Delete the original made from the master.
Open redis
3. In the real machine (mounting mariadb 250)
First, empty the environment
Authorization allows front-end server can call back the database
The test in the test data into the database
mysql -pwestos1234 < test.php
When accessed in a browser (server1). Discover at this time the client access to the information mysql database
because the database redis there are no data, so the first would go to the mysql database to get data
when you can see a second time to refresh the visit is to take data from the redis