Redis usage summary, redis Summary
1. Install Redis
Redis installation is very simple, and Redis is not dependent on other environments and standard libraries, so it is easy to get started. This may be one of the reasons for its popularity. For the convenience of the test, all tests are performed in windows. Download Redis for Windows.
Redis. windows. conf is the configuration file of redis.
Redis-server.exe server side.
Redis-cli command line client.
Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration.
2. Start the service
Enter the following command in the command line: redis-server redis. windows. conf.
You can also save the command as the file startup. bat, which can be started directly next time.
If you are prompted that the redis-server is not an internal command. Add the directory to the environment variable.
3. redis-related configuration
1. port number, for example, 6379
2. Access address bound to the bind instance 127.0.0.1
3. requirepass Password
4. Remember to open this configuration node for maxheap. Otherwise, the redis service cannot be started. For example, maxheap 1024000000
5. timeout: Request timeout
6. logfile: Location of the log file
7. databases: number of databases Enabled
8. dbfilename: Data snapshot file name (only file name, excluding directory)
4. connection test
Enter the following command in the command line: redis-cli-h 127.0.0.1-p 6379
The parameters are host and port respectively. If the password is set, you must add-a 123456,123456 as the logon password. Otherwise, you will be prompted that you do not have the permission to log on to the system.
As shown in.
5. Master/Slave Configuration
Redis, like MySQL, has a very powerful master-slave replication function. It also supports a master with multiple slave instances, and a single slave with multiple slave instances, thus forming a powerful multi-level server cluster architecture.
Redis's master-slave replication is asynchronous and does not affect the operation of the master, so it does not reduce the processing performance of redis. In the Master-Slave architecture, you can consider disabling the data persistence function of the Master to only make the Slave persistent, which can improve the processing performance of the Master server. At the same time, Slave is read-only, which can prevent the data cached by Slave from being mistakenly modified.
In actual production, the master-slave architecture installs the corresponding Redis service on several different servers. For the convenience of testing, the configuration of master-slave backup on my side is all tested on my Windows host.
1. install two Redis instances, Master and Slave. Set the Master port to 6379 and the Slave port to 6380. Bind is set to 127.0.0.1.
2. Add the slaveof 127.0.0.1 6380 configuration in the Slave instance.
After the configuration is complete, start the two instances. If the following content is output, the master-slave replication architecture has been configured successfully.
Note: For testing on the same computer, the ports of the Master and Slave should not be the same; otherwise, the two instances cannot be started at the same time.
3. On the command line, connect the Master server and the Slave server respectively. Write the data to the cache on the Master node and read the data from the Slave. As shown in:
Note: slave can only read and cannot write data.