Redis is a high-performance Key-value database. The emergence of redis largely compensates for the shortage of keyValue storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides python, Ruby, Erlang, and PHP clients for ease of use.
Performance test results:
The set operation is performed 110000 times per second, and the get operation is performed 81000 times per second. The server configuration is as follows:
Linux 2.6, Xeon x3320 2.5 GHz.
The stackoverflow website uses redis as the cache server.
Redis can set a master-slave replication. For details, see redis. conf.
################################# Replication ###### ########################## master-slave replication. use slaveof to make a redis instance a copy of # Another redis server. note that the configuration is local to the slave # So for example it is possible to configure the slave to save the DB with a # different interval, or to listen to another port, and so on. # slaveof <masterip> <masterport># Master service IP address and port# If the master is password protected (using the "requirepass" configuration # directive below) it is possible to tell the slave to authenticate before # Starting the replication synchronization process, otherwise the master will # refuse the slave request. # masterauth <master-Password># If the master password is set, slave needs to be authenticated# When a slave loses its connection with the master, or when the replication # is still in progress, the slave can act in two different ways: #1) if slave-serve-stale-data is set to 'yes' (the default) the slave will # Still reply to client requests, possibly with out of date data, or the # data set may just be empty if this is the first synchronization. #2) if slave-serve-stale-data is set to 'no' the slave will reply with # An error "sync with Master in progress" to all the kind of commands # But to Info and slaveof. #
# When slave loses its connection to the master or is being copied, if yes, slave will respond to the client request, and the data may not be synchronized or even have no data. If no, slave will return an error "sync with Master in progress"
Slave-serve-stale-data Yes
# You can configure a slave instance to accept writes or not. writing against # A slave instance may be useful to store some ephemeral data (because data # written on a slave will be easily deleted after Resync with the master) but # may also cause problems if clients are writing to it because of a # misconfiguration. # Since redis 2.6 by default slaves are read-only. # Note: Read Only slaves are not designed to be exposed to untrusted clients # on the Internet. it's just a protection layer against misuse of the instance. # Still a read only slave exports by default all the administrative commands # such as config, debug, and so forth. to a limited extend you can improve # security of read only slaves using 'rename-command' to shadow all the # administrative/Dangerous commands.
Slave-read-only yes# Read-only from the slave server, not writable# Slaves send pings to server in a predefined interval. it's possible to change # This interval with the repl_ping_slave_period option. the default value is 10 # seconds. # repl-ping-slave-period 10 # The following option sets a timeout for both bulk transfer I/O timeout and # master data or ping response timeout. the default value is 60 seconds. # It is important to make sure that this value is greate R than the value # specified for REPL-ping-slave-period otherwise a timeout will be detected # every time there is low traffic between the master and the slave. # repl-timeout 60 # disable tcp_nodelay on the slave socket after sync? # If you select "yes" redis will use a smaller number of TCP packets and # less bandwidth to send data to slaves. but this can add a delay for # the data to appear on the slave side, up to 40 milliseconds with # linux kernels using a default configuration. # If you select "no" the delay for data to appear on the slave side will # Be Forced CED but more bandwidth will be used for replication. # By default we optimize for low latency, but in very high traffic conditions # or when the master and slaves are running hops away, turning this to "yes" may # Be A Good Idea. repl-Disable-TCP-nodelay no # The slave priority is an integer number published by redis In the info output. # It is used by redis sentinel in order to select a slave to promote into a # Master if the master is no longer working correctly. # A slave with a low priority number is considered better for promotion, so # For instance if there are three slaves with priority 10,100, 25 Sentinel will # Pick the one wtih Priority 10, that is the lowest. # however a special priority of 0 marks the slave as not able to perform the # role of master, so a slave with priority of 0 will never be selected by # redis sentinel for promotion. # by default the priority is 100. slave-priority 100# If the master node cannot work normally, in multiple Server Load balancer instances, select one Server Load balancer instance with the smallest priority value as the master node. If the priority value is 0, the master node cannot be upgraded.
After reading the default configuration above, it is also easy to understand. After modification, you can configure master-slave replication. With slaveof <masterip> <masterport>, it becomes a slave server, not a master server.
The master server, slave server, has the same configuration but only modifies/etc/redis. conf.
slaveof 192.168.1.33 6379
Then enable the redis service on the slave server.
Test
# Master server redis-cli-P 6379 set Hello world # slave server redis-cli-P 6379 get hello "world" # master server redis-cli-P 6379 set Hello World2 # slave server redis-cli-P 6379 get hello "World2" redis-cli-P 6379 set Hello World (error) readonly you can't write against a read only slave. # The Master/Slave redis server is successfully configured. It's easy.
Because one slave server is read-only in the configuration, the slave server cannot set data and can only read data.
Redis master-slave Replication