Introduction to the NoSQL Redis:
Remote Rerictionry Server is a persistent database storage system based on Key-value key-value pairs, and the Redis and memcached caching services are similar.
However, Redis supports a richer variety of data storage types, including string, list, set, and Zset, which all support Push/pop, Add/remove
And take the intersection, the set and the difference set and the richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways.
Like the memcached cache service, in order to ensure efficiency, the data is cached in memory to provide services, and memcached is different (memcached currently seems to support persistence, not verified), Redis persistence
The cache service also periodically writes the updated data to the disk and appends the modified operation record to the file, which is more advantageous than memcached,
Redis also supports Master-slave synchronization. The emergence of redis, to some extent, make up for the memcached of such key-value memory cache service,
In some cases can be a good complement to the relational database, Redis provides python,ruby,php and other clients, easy to use
Http://www.redis.io/documentation
http://www.redis.cn
Redis Benefits:
Persistence: Unlike memcached, you can persist data storage
High performance: Redis can support more than 100k+ per second read and write frequency.
Rich data types: Redis supports data type operations such as binary string,lists,hashes,sets and ordered sets.
Atom: All operations of Redis are atomic, and Redis supports atomic execution of several operations.
Rich features: Redis also holds the publish/subscribe, notifications, key expiration and so on features.
Redis supports master-slave replication of different machines
Redis Data type:
String
Hash
List
Set
Sorted set
Application Scenarios for Redis:
Traditional mysql+memcached Web site architecture encounters problems
MySQL database is actually suitable for the massive data storage, plus through memcached to store the hotspot data in the memory cache, to speed up the purpose of data access.
Most companies have used such architectures, but as the volume of business data continues to increase, and as traffic continues to grow, many problems can leak out.
1. It is necessary to continuously disassemble the MySQL database, memcached also need to continuously follow the expansion, expansion and maintenance work occupy a large number of development operations time
Data consistency problem with MySQL database in 2.memcached
3.memcached data hit rate is low or down, resulting in massive access to the database directly, resulting in MySQL unable to support business access
4. Cross-room cache synchronization Consistency problem
The best application scenario for Redis:
1.redis Best Use scenario is all data in-memory
2.redis more scenes are used as a substitute for memcached and need development support
3. Using Redis is more appropriate when you need more data type support than Key-value
4. Support Persistence
5. Scenarios requiring load balancing (Redis master-Slave synchronization)
Redis Installation:
Get Redis:
Cd/usr/local/src/wget http://download.redis.io/releases/redis-3.0.7.tar.gz
Installation:
TAR-ZXF redis-3.0.7.tar.gzcd REDIS-3.0.7CP redis.conf/etc/redis.confmake malloc=jemallocmake PREFIX=/usr/local/ Redis Install
To configure environment variables:
Echo ' Path=/usr/local/redis/bin: $PATH ' >>/etc/profile
. /etc/profile
To start Redis:
Nohup redis-server/etc/redis.conf &
Use of client Tools:
Redis-cli-h 127.0.0.1-p 6379
Common commands for clients:
Set no002 Sunwukong #设置一个键, with a value of Sunwukongget no002# gets the value of the key no002 del no002# Delete the value of no002 key * #获取当前reds下的所有keyinfo #查看当前redis的状态信息
Description of Redis master-slave replication:
Redis's master-slave replication is very powerful, a master can have multiple slave, and a slave can have more than one slave, so continue to form a powerful multi-level server clusterArchitecture. Here are some of the features of Redis master-slave replication:
1.master can have multiple slave
2. In addition to multiple slave connected to the same master, slave can also connect other slave to form a graphic structure
3. Master-slave replication does not block primary. This means that when one or more slave and master synchronize data for the first time, master can continue to process requests from the client. Conversely, slave will block requests that cannot process the client when the data is first synchronized.
4. Master-slave replication can be used to improve the scalability of the system, we can use multiple slave dedicated to client read requests, such as the sort operation can be handled using slave. can also be used to do simple data redundancy
5. You can disable data persistence in master, just comment out all the save configurations in the master configuration file and configure data persistence on slave only.
The following describes the process of master-slave replication
when the slave server is set up, slave will establish a connection to master and then send the Sync command. Whether the connection is established for the first time or after a disconnected connection, master initiates a background process that willDatabaseThe snapshot is saved to a file, and the master master process starts collecting new write commands and caches them. After the background process finishes writing the file, master sends the file to Slave,slave to save the file to disk, and then loads it into the memory recovery database snapshot to slave. The master then forwards the cached command to slave. and subsequent master commands are sent to the slave by the connection that was started to be established. Commands that synchronize data from master to slave and commands sent from the client use the same protocol format. Slave can automatically reestablish a connection when master and slave are disconnected. If master receives multiple slave simultaneous connection commands at the same time, it will only use the START process to write database mirroring and then send it to all slave.
Redis Master-slave replication configuration
Redis from Operation:
[Email protected] ~]# cat/etc/redis.conf |grep ' slaveof ' # master-slave replication. Use slaveof to make a Redis instance a copy of# slaveof <masterip> <masterport>
Add a new row under this line
Slaveof 192.168.1.100 6379
Save restart and the Redis service from the following information indicates that master-slave synchronization is normal
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/05/wKioL1eDbAGxsdKsAAQgJ2xB8FQ547.png-wh_500x0-wm_3 -wmp_4-s_2244421217.png "style=" Float:none; "title=" Main. png "alt=" wkiol1edbagxsdksaaqgj2xb8fq547.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/06/wKiom1eDbASB2t8hAAQkNfKf0PE513.png-wh_500x0-wm_3 -wmp_4-s_1396005675.png "style=" Float:none; "title=" from. png "alt=" wkiom1edbasb2t8haaqknfkf0pe513.png-wh_50 "/>
Verify:
Create a data on the Redis master server
[[email protected] ~]# redis-cli 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set MyData john.gouok127 .0.0.1:6379> get MyData "John.gou" 127.0.0.1:6379>
Validating on Redis slave server
[[email protected] ~]# redis-cli 127.0.0.1:6379> get MyData "John.gou" 127.0.0.1:6379> set MyKey 123 (Error) READONLY You can ' t write against a read only slave.
PS: You can see that the data from the server is already synchronized and you cannot add data from it. Redis master-Slave synchronization setup completed
This blog's Redis master-Slave synchronization benefits and synchronization process are transcribed in http://blog.csdn.net/yangzhenzhen/article/details/8512292
This article is from the "beginner's mind, always" blog, please be sure to keep this source http://gouyc.blog.51cto.com/1594451/1825516
Redis Introduction, master-slave configuration