redis+mysql+nginx+php

Source: Internet
Author: User
Tags data structures redis server

A brief introduction to Redis1 Redis

Redis is fully open source free, adheres to the BSD protocol and is a high-performance Key-value database.
Redis and other Key-value cache products have the following three features:
Redis supports data persistence, which saves data in memory on disk and can be loaded again for use when restarting.
Redis not only supports simple key-value types of data, but also provides storage of data structures such as List,set,zset,hash.
Redis supports backup of data, that is, Master-slave mode of data backup.

2 Redis Benefits

The performance is very high –redis can read the speed is 110,000 times/s, the write speed is 81,000 times/s.
Rich data types –redis support binary case Strings, Lists, hashes, sets and Ordered sets data type operations.
Atomic –redis All operations are atomic, meaning either successful execution or failure to execute at all. A single operation is atomic. Multiple operations also support transactions, namely atomicity, wrapped by multi and EXEC commands.
Rich features –redis also supports publish/subscribe, notifications, key expiration, and more.

3 Redis compared to other key-value storage

Redis has more complex data structures and provides atomic manipulation of them, which is a different evolutionary path from other databases. The data types of Redis are based on basic data structures and are transparent to programmers without the need for additional abstraction.
Redis runs in memory but can be persisted to disk, so it is necessary to weigh the memory when writing to different datasets at high speed because the amount of data cannot be larger than the hardware memory. Another advantage of the in-memory database is that it is very simple to operate in memory compared to the same complex data structure on disk, so Redis can do a lot of things that are internally complex. At the same time, they are compact in the form of disks, because they do not have to be randomly accessed.

Two experimental environment:

Software:
Links: Https://pan.baidu.com/s/1VJ91A6pCLqDfbzsL2OPyXA
Password: bu2x

1 Installing the Software 1 installing PHP and modifying the time zone





See if it adds a MySQL module

2 Installing and configuring Nginx modules






Add PHP Home page:

View:

3 loading Redis-related modules on PHP:











4 Installing Redis on Server2






2 Configuring the 1 Server3-side configuration link redis and MySQL

2 server 1-side MySQL-side configuration:



3 Test:



Back-End Database modification data:


Front View:

No change, no response due to no triggering update mechanism:

3 Configuring Trigger Updates:

Gearman Frame Composition:

Gearman is a distributed task-distribution framework that supports:
The Gearman Job Server:gearman Core program needs to be compiled and installed and run in the background as a daemon.
Gearman Client: Can be understood as a requester of a task.
Gearman Worker: The real performer of the task, generally needs to write its own specific logic and through the daemon way
Run, the Gearman Worker receives the task content passed by the Gearman Client, which is processed sequentially.

Approximate process:
The following MySQL trigger to write is equivalent to the Gearman client. modifying tables, inserting tables is equivalent to directly
issued a task. The relational data is then mapped to JSON format through the Lib_mysqludf_json UDF library function, and then
The task is added to the Gearman task queue through the GEARMAN-MYSQL-UDF plug-in, and finally through
redis_worker.php, the worker side of Gearman, completes the Redis database update.
The processing of a Gearman request involves three roles: Client-to-Job Worker.
Client: The initiator of the request, which can be a c,php,perl,mysql UDF, and so on.
Job: The dispatcher of the request is responsible for coordinating the forwarding of requests from the Client to the appropriate work.
Worker: The handler for the request, which can be c,php,perl, and so on.
Because Client,worker does not restrict the use of the same language, it facilitates integration between multiple languages and multiple systems.
Even by adding more workers, we can easily implement the distributed load-balancing architecture of the application.

1 Installation of Gearmand:

Responsible for receiving data from the front-end Gearman client in the form of daemons

2 Gearman installation, plug-in for PHP,





To see if the module was successfully installed

3 Configuring the PHP link Redis:



specified by specifying the IP address and port of the Redis server

Enter backstage

Send the configuration file to the server1 where MySQL data resides

4 Installing the MySQL-related Configuration Pack 1 The Lib_mysqludf_json UDF library function maps the relational data to JSON format. Typically, the data in the database is mapped

The shot is in JSON format and is converted by a program.





2 Installing the GEARMAN-MYSQL-UDF:

This plugin is used to manage the distributed queues that call Gearman.

5 Modify to create a trigger template


6 Registering the UDF function:

7 Create a trigger and view its status

8 Data Insertion test on the service side


Client to see if insert succeeded

redis+mysql+nginx+php

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.