## Project background: The company’s sales ranking data has reached more than 20 million, and the waiting time for querying the database is increasing. Therefore, I want to optimize the query speed. ####1. Reasonable establishment of index according to the design of the table, reasonable establishment of relevant index, because it involves some company secrets, here is not convenient to write too much, interested children shoes can search information by themselves. ####2. Reasonable table division According to business requirements, the data that is not commonly used is divided into another table, for example, every three quarters or a year. If the data goes back several years, it can be maintained in another database. Focus on the immediate future. ####3. Cache technology can cache some frequently queried data. Redis, a high-performance key-value database, is used this time. The reason:

High performance – Redis can read 110,000 times /s and write 81,000 times /s.

Rich data types – Redis supports binary case Strings, Lists, Hashes, Sets and Ordered Sets data type operations.

Atomic – All operations in Redis are atomic, and Redis also supports atomic execution after several operations have been combined.

Rich features – Redis also supports publish/subscribe, notifications, key expiration, and more.

This is a practical example of using PHP to link to Redis. 1. To making find relevant phpredis https://github.com/phpredis/phpredis/releases version number

Place the relevant PHP plug-in in the relevant Ext path.


2. Check whether the plug-in is configured successfully.


3. Start the redis

1. Run redis.windows.conf

2. Start another command window, redis-cli

3. Write PHP link Redis

Code:

<? php //connect redis //$redis =new Redis();
	// $redis->connect('127.0.0.1', 6379); //echo "Connect to server sucessfully<br>";

	// echo "Server is running : ".$redis->ping(); // Connect to the local Redis service$redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server sucessfully<hr>"; // Store data to the list //$redis->lpush("tutorial-list"."Redis");
   // $redis->lpush("tutorial-list"."Mongodb");
   // $redis->lpush("tutorial-list"."Mysql"); // Get the stored data and output it$arList = $redis->lrange("tutorial-list", 0 ,50);
   echo "Stored string in redis";
   print_r($arList); ? >Copy the code


Redis simple set data PHP:

<? PHP // Connect to the local Redis service$redis = new Redis();
   $redis->connect('127.0.0.1', 6379);

   $redis->set('cc'31);if ($redis) {
      echo "success";
   }

?>
Copy the code


Redis simple get data PHP way

<? PHP // Connect to the local Redis service$redis = new Redis();
   $redis->connect('127.0.0.1', 6379);

  echo  $redis->get('cc'); ? >Copy the code

Data obtained through PHP.