MongoDB and memcached are not something within a category. MongoDB is a document-type non-relational database, its advantage is that the query function is more powerful, can store massive data. MongoDB and memcached do not exist who replace who's problem.
And memcached is closer to Redis. They are in-memory database, the data is stored in memory, through TCP direct access, the advantage is fast, high concurrency, the disadvantage is that the data type is limited, the query function is not strong, generally used as a cache. In our team project, we started with memcached and later with Redis instead.
Compared to memcached:
1. Redis has a persistence mechanism that can periodically persist the data in memory to the hard disk.
2, Redis has the Binlog function, can write all operations to the log, when the Redis failure, can follow the Binlog data recovery.
3, Redis support virtual memory, can limit the size of RAM, when the data exceeds the threshold, the most infrequently used data in memory is saved to the paging file of the hard disk by an algorithm like LRU.
4. Redis native supports more data types and uses more space for imagination.
5, a friend mentioned in front of a consistent hash, used in Redis sharding, generally in the load is very high need to expand the level of use. We have not used this aspect of the function, the general project, stand alone enough to support the concurrency. Redis 3.0 will launch cluster, which is more powerful.
6. Performance
The Redis authors say that the performance is average to a single core, and Redis is better in the case of small pieces of data. Why do you say that, the reason is that Redis is a single-threaded operation.
Because it is single-threaded, the overall performance will certainly be low compared to memcached multithreading.
Because it is single-threaded, IO is serialized, network IO, and memory Io, so performance is affected when the single data is too large to be followed up by waiting for all of the IO of a command to complete for subsequent commands.
Brief introduction
MongoDB is more like MySQL, support field index, cursor operation, the advantage is that the query is more powerful, good at querying JSON data, can store large amounts of data, but does not support transactions.
MySQL is significantly less efficient when it comes to large data volumes, and MongoDB is more of a substitute for relational databases.
Memory management mechanism
The Redis data all exists in memory and is written to disk on a regular basis, and when memory is insufficient, the specified LRU algorithm can be selected to delete the data.
MongoDB data exists in memory, implemented by Linux system Mmap, when the memory is not enough, only the hotspot data into memory, the other data exists disk.
Supported data structures
Redis supports rich data structures, including hash, set, list, and so on.
MONGODB data structure is relatively single, but support rich data expression, index, most similar relational database, support query language is very rich.
Performance
Both performance is relatively high, should say is not a bottleneck.
Reliability
Both of them support persistence.
Cluster
MongoDB clustering technology is relatively mature, Redis starting from 3.0 support cluster.
Scenario Not applicable
? Operations that require the use of complex SQL
? Transactional systems
Memcached, Redis, MongoDB differences