1, performance
Both are relatively high, and performance should not be our bottleneck.
Generally speaking, in TPS, redis is similar to memcache, but larger than mongodb.
2. Convenient operation
Memcache has only one data structure. (key value)
Redis is more abundant, in terms of data operation, Redis is better, network IO times are less, and list, set,
Storage of hash and other data structures.
Mongodb supports rich data expression and index, which is most similar to relational database and supports very rich query languages.
3. The size of memory space and the size of data.
Redis added its own VM feature after version 2.0, which broke through the limitation of physical memory. You can set key values.
Cycle time (similar to memcache)
Memcache can modify the maximum available memory and adopt LRU algorithm. Memcached agent software magent, such as establishing
10 4G Memcache cluster is equivalent to 40G. magent-s 10. 1.2 . 1-s 1.2 . 2: 1 12 1 1-b
10.1.2.3:14000 MongoDB is suitable for storing a large amount of data. It relies on the operating system VM for memory management, and the memory consumption is also very serious.
Don't be with other services.
4. Availability (single point problem)
For single-point problems,
Redis, relying on the client to realize distributed reading and writing; In master-slave replication, every time the slave node reconnects to the master node, it depends on integer.
Snapshots, due to performance and efficiency problems, have no incremental replication.
Therefore, the single point problem is more complicated; Automatic fragmentation is not supported, and it depends on the program to set a consistent hash mechanism.
An alternative method is to make active replication (multi-storage) by yourself, instead of the replication mechanism of redis itself, or change it to.
The way of incremental replication (which needs to be realized by itself), consistency problems and performance tradeoffs.
Memcache itself has no data redundancy mechanism and is unnecessary; To prevent failures, use a mature hash or ring.
In order to solve the jitter problem caused by single point failure, an algorithm is proposed.
MongoDB supports master-slave, replicaset (internal paxos election algorithm, automatic fault recovery) and automatic segmentation mechanism, which shields the failover and segmentation mechanism for the client.
5. Reliability (Persistence)
For data persistence and data recovery,
Redis support (snapshot, aof): depending on snapshots to achieve persistence, AOF enhances reliability, but it also affects performance.
loudly
Memcache is not supported and is usually used for caching to improve performance;
MongoDB has adopted binlog mode to support persistent reliability since 1.8 version.
6. Data consistency (transaction support)
Memcache uses cas to ensure consistency in concurrent scenarios. Redis transaction support is weak and can only guarantee the continuous execution of each operation in the transaction.
MongoDB does not support transactions.
7. Data analysis
MongoDB has built-in data analysis (mapreduce) function, but others don't support it.
8. Application scenarios
Redis: More performance operations and less data operations.
Memcache: used to reduce database load and improve performance in dynamic systems; Do caching to improve performance (suitable for more reading and writing)
Less, for a large number of data, you can use fragmentation)
MongoDB: It mainly solves the problem of access efficiency of massive data.
Table comparison:
Memory database
When defining values, data types should be fixed. Data type is not required.
There are strings, linked lists, sets and ordered sets.
Virtual memory does not support.
Expiration policy support support
Distributed master-slave, one master-slave or one master-slave.
Storage data security does not support saving to dump.rdb.
Disaster recovery does not support data recovery by attaching files only (aof).
perform
1, type-memcache and redis all store data in memory, so they are in-memory databases. Of course, memcache can also be used to cache other things, such as pictures and so on.
2. Data type-Memcache specifies the byte length of data when adding data, but redis does not.
3. Virtual memory-When the physical memory runs out, you can exchange some values that have not been used for a long time to disk.
4. Expiration policy-Memcache is specified when setting, for example, set key 1 0 0 8, that is, it will never expire. Redis can connect
For example, set the expiration time, such as expiration name 10.
5. The distributed memcache cluster uses magent as the master node and multiple slave nodes; Redis can be a master or a slave. coconut tree
There is a master and a slave.
6, storage data security-power failure MemCache is broken, the data is gone; Redis can be saved to disk regularly.
7, disaster tolerance-memcache ditto, redis loss can be recovered through aof.
Memecache port11211.
Yum -y installs memory cache.
Yum -y installs php-pecl-memcache.
/etc/init . d/memcached start memcached-d-P 1 1 1-u memcached-m 64-c 1024-P/var/run/memcached/memcached . PID
-d Start a daemon.
-p port
-m allocated memory is m.
-c maximum running concurrency-pid of -P memcache
//0 compress (whether MEMCACHE_COMPRESSED) 30 seconds expiration time.
//Deleting 5 is a timeout.
$memcache = new memcache; $ memcache-& gt; Connection ('127.0.0. 1',11211); $ memcache-& gt; Set ('name',' Yang', 0, 30);
If (! $ memcache-& gt; Add ('Name',' Susan', 0,30)) {
///echo‘' Susan exists'; } $ memcache-& gt; Replace ('name',' lion', 0,300); echo $ memcache-& gt; get(' name ');
//$ memcache-& gt; Delete ('name', 5);
printf " stats \ r \ n " | NC 127 . 0 . 0 . 1 1 12 1 1
Telnet local host11211statquit.
Redis's profile port 6379
/etc/Redis.conf starts Redis.
Redis-server /etc/redis.conf inserts a value.
Redis-cli sets test "phper.yang" to get the key value.
Redis-cli get test closes redis.
Redis-cli shut down shut down all
Redis-cli -p 6379 close Server-side programming language (abbreviation of professional hypertext preprocessor)
$ redis = new
redis(); $ redis-& gt; Connection ('127.0.0. 1', 6379); $ redis-& gt; Settings ('test',
hello World’); echo $ redis-& gt; get(' test '); Mongodb
Apt-get installs mongo mongo to enter the shell command line.
Pecl installation of mongo Mongodb is similar to the phpmyadmin operating platform RockMongo.