Redis+mysql+NGINX+PHP

A Redis

1 Introduction to Redis

Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.
Redis and other key-value caching products have the following three characteristics:
Redis supports data persistence, which can save data in memory on disk, and can be loaded again for use when restarted.
Redis not only supports simple key-value type data, but also provides storage of data structures such as list, set, zset, and hash.
Redis supports data backup, that is, data backup in master-slave mode.

2 Redis Advantages

Extremely high performance - Redis can read at 110,000 times/s and write at 81,000 times/s.
Rich data types – Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations for binary cases.
Atomic – All operations in Redis are atomic, meaning that they either execute successfully or fail to execute at all. A single operation is atomic. Transactions are also supported for multiple operations, i.e. atomicity, wrapped by MULTI and EXEC instructions.
Rich features – Redis also supports publish/subscribe, notifications, key expiration and more.

3 Comparison of Redis and other key-value stores

Redis has more complex data structures and provides atomic operations on them, which is an evolutionary path different from other databases. Redis data types are based on basic data structures and are transparent to programmers without additional abstraction.
Redis runs in memory but can be persisted to disk, so when reading and writing different data sets at high speed, memory needs to be weighed, because the amount of data cannot be larger than hardware memory. Another advantage in terms of in-memory databases is that it is very simple to operate in memory compared to the same complex data structures on disk, so Redis can do a lot of things with a lot of internal complexity. At the same time, they are compact in terms of on-disk format and are generated appending because they do not require random access.

Two experimental environment:

Software download address:
link: https://pan.baidu.com/s/1VJ91A6pCLqDfbzsL2OPyXA
Password: bu2x
Redis+mysql+NGINX+PHP

1 Software installation

1 Install php and modify the time zone

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Check if it has added the mysql module
Redis+mysql+NGINX+PHP

2 Install and configure NGINX modules

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Add PHP home page:
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

Check:
Redis+mysql+NGINX+PHP

3 Load redis-related modules on PHP:

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

4 Install redis on server2

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

2 Configuration

1 server3 side configuration link redis and mysql

Redis+mysql+NGINX+PHP

2 server 1 side mysql side configuration:

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

3 tests:

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Backend database modifies data:
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
frontend view:
Redis+mysql+NGINX+PHP
no change, no response since no update mechanism is triggered:

3 Configure the trigger update:

Gearman architecture diagram:
Redis+mysql+NGINX+PHP
Gearman is a distributed task distribution framework:
Gearman Job Server: Gearman core program, which needs to be compiled and installed and run in the background as a daemon process.
Gearman Client: It can be understood as the requester of the task.
Gearman Worker: The real executor of the task, generally needs to write the specific logic and
run it through the daemon process. After the Gearman Worker receives the task content passed by the Gearman Client, it will process it in order.

Rough process:
The mysql trigger to be written below is equivalent to Gearman's client. Modifying the table and inserting the table is equivalent to directly
issuing the task. Then use the lib_mysqludf_json UDF library function to map the relational data to JSON format, then
add the task to Gearman's task queue through the gearman-mysql-udf plug-in, and finally
complete the redis database through redis_worker.php, which is the worker side of Gearman. renew.
The processing of a Gearman request involves three roles: Client -> Job -> Worker.
Client: The initiator of the request, which can be C, PHP, Perl, MySQL UDF, etc.
Job: The scheduler of the request, which is responsible for coordinating forwarding the request sent by the Client to the appropriate Work.
Worker: The handler of the request, which can be C, PHP, Perl, etc.
Because Client and Worker are not restricted to use the same language, it is conducive to the integration between multi-language and multi-system.
Even we can easily implement the distributed load balancing architecture of the application by adding more workers.

1 Installation of gearmand:

Responsible for receiving the data of the front-end gearman client, in the form of guarding
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

2 gearman installation, plugin for php,

Redis+mysql+NGINX+PHP

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Check if the module is installed successfully
Redis+mysql+NGINX+PHP

3 Configure PHP to link Redis:

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Specify by specifying the IP address and port of the redis server. Enter
Redis+mysql+NGINX+PHP
the background and
Redis+mysql+NGINX+PHP
send the configuration file to server1 where the mysql data is located.
Redis+mysql+NGINX+PHP

4 Install mysql related configuration packages

1 The lib_mysqludf_json UDF library function maps relational data to JSON format. Usually, the data map in the database

The project is in JSON format, which is converted by the program.
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

2 Install gearman-mysql-udf:

This plugin is used to manage a distributed queue of calls to Gearman.
Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

5 Modify to create trigger template

Redis+mysql+NGINX+PHP
Redis+mysql+NGINX+PHP

6 Register the UDF function:

Redis+mysql+NGINX+PHP

7 Create a trigger and view its status

Redis+mysql+NGINX+PHP

8 Server-side data insertion test

Redis+mysql+NGINX+PHP
The client checks whether the insertion is successful
Redis+mysql+NGINX+PHP

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325153231&siteId=291194637