Recently work with some of the things about Redis, I also looked up some information on the Internet, found that a lot of Daniel Summary is very good, they have to learn the bit by bit record down.
We looked at some of the uses of Redis, including Redis installation, Redis Singleton, Redis clustering, and a simple understanding of redis slices. In fact, it is very convenient and very simple to use. For some of the more esoteric things have not been studied, but some simple ways to use.
Let's go to the following:
One, single-machine deployment
First of all, what is Redis? Redis should be a key-value-like storage system, and of course he supports several data structures, such as String, List, set, Zset, hash. It is generally used as a data cache during the work process, and of course Redis supports persistence.
Because it is installed and learning on the Mac, so this side only about some of the installation of the Mac on the deployment, and basically similar to the Linux environment.
About Redis, there are three things to install before you learn: 1, Ruby 2, Rubygem 3, Redis. Where Ruby and Rubygem are understood as plug-ins for the moment, what needs to be installed will be explained during the deployment process.
First, to download the Redis, there are many examples on the Internet, here is the redis3.0.2 version, download the local decompression after the completion of the directory to enter the SRC directory to enter the make command for Redis installation. Note that when it comes to this side of a small problem, reported a failure to find the make command error, the final solution is the Terminal Input command Xcode-select--install to install the command line plug-in, Of course, there are many solutions on the Internet is to download a Xcode software and then operate inside, this method has not been tried, compared to xcode-select--install should be simpler.
After the installation completes Redis, try to start the service and enter the SRC directory input:./redis-server command to start Redis, as after startup.
This will start the completion. Here is the connection Redis, OK, we temporarily reopen a terminal, and then again into the SRC directory below, is not feeling more troublesome, a little later will be explained slowly, you can start the background redis. Under the SRC directory, enter the./redis.cli connection into Redis.
Okay, so far, the installation of Redis, the start-up and the connection is done. This way, I think we need to be specific about the two commands for Redis boot and connect, these two commands are actually parameters, and if you enter only the./redis-server command when Redis boots, the Redis.config configuration file under the Redis installation directory is loaded by default. The contents of this configuration file I removed some, only to leave a few common configuration, such as.
A parameter description for one argument:
Daemonize: This is to set up the Redis background boot configuration, if it is false, the above start Redis can not continue to enter the command, you have to re-open a terminal. Of course I configured yes in this way and it turned into a background run.
The port number of the Port:redis, for the client to connect, the default is generally 6379.
Cluster-enabled: Set to ture indicates Reids cluster is enabled.
Cluster-config-file:redis Cluster configuration file information
Cluster-node-timeout: Connection time-out.
OK, let's test the Redis that just started, put a few values inside and then take out.
Above is the Redis default startup, now I need to modify the Redis port number, default is 6379, The port number configuration is inside the redis.conf file, when the boot time if redis.server after the default is the installation root directory redis.conf configuration file, now the root directory under the copy of a redis.conf to SRC open Modify the port number information
Change the port number to 6378, and change the daemonize to Yes, and the Redis command starts with parameters, which should be./redis.server./redis.conf (The Redis profile just modified).
You can see that the Redis boot does not display boot information, which is the effect of configuring Daemonize to Yes,redis in the background. Connecting to Redis also requires a connection via the port number:
2. Redis Master-slave replication:
Let's look at some of the features of Redis master and Slave:
1. Redis uses asynchronous replication. Starting with Redis 2.8, slave also periodically tells master the current amount of data.
2, a master can have more than one slave, and synchronization with the slave data is asynchronous.
3. Slave can receive connections from other slave.
Well, let's go straight to the experiment.
First, Redis master-slave replication
First, three instances are opened and the commands are:
Redis-server--port 1001--daemonize Yes
Redis-server--port 1002--daemonize Yes
Redis-server--port 1003--daemonize Yes
This explains that when Redis starts, the port number defaults to 6379, and we can modify the configuration file to modify the port number and background boot configuration of the boot instance. Another method is the above command mode, in the command with the parameter--port 1001 indicates that the boot port is 1001,--daemonize yes for the default background boot. Okay, now we're done. Three port numbers are 1001, 1002, 1003 instances, input PS Aux|grep Redis can see the current Redis process
Since it is a master-slave replication, then we have to establish a master-slave relationship, here is to set 9002 and 9003 to 9001 of the subordinate Redis, enter the connection into 9002 and 9003, enter slaveof 127.0.0.1 1001 can:
After setting up the master-slave configuration, let's test it, first look at the three machines there is no "test01" this data,
There are no data in all three instances, and now we put a value into the master Redis,
Again on 10001, 02, 03 to see if there are already values.
You can see that the values placed on port 9001 have been synchronized to 9002 and 9003. Another point to note is that in Redis, slave can only read and write values.
Redis easy to understand one: (Deployment/master-slave replication)