接触MongoDB和Redis有段时间了,只知道他们都是KV型数据库,但是异同点却不是很清楚。google了下,看到有篇英文版的对比:
英文来自——http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis/
于是就做了个表格,加上自己使用的一些体会,就有了此文。
MongoDB |
Redis (V2.4) |
说明 |
Written in: C++ |
Written in: C/C++ |
|
Main point:Retains some friendly properties of SQL. (Query, index) |
Main point: Blazing fast |
MongoDB保留类似SQL的属性, 例如:show dbs;db.test.find() Redis—快 |
License: AGPL (Drivers: Apache) |
License: BSD |
|
Protocol: Custom, binary (BSON) |
Protocol: Telnet-like |
|
Master/slave replication (auto failover with replica sets) 主从复制+replica sets |
Master-slave replication 主从复制 |
|
Sharding built-in 内置的sharding分片功能 |
MongoDB一般会使用replica sets和sharding功能结合,replica sets侧重高可用性及高可靠性,而sharding侧重于性能、易扩展 |
|
Queries are javascript expressions 查询是javascript语句 |
||
Run arbitrary javascript functions server-side 运行任意的server-side javascript函数 |
||
Better update-in-place than CouchDB update-in-place的支持比CouchDB更好 |
||
Uses memory mapped files for data storage 使用内存转储文件做数据存储
|
Disk-backed in-memory database, Currently without disk-swap (VM and Diskstore were abandoned) 磁盘做后备、内存数据库 目前2.4版本不带disk-swap(虚拟内存和diskstore被舍弃了) |
|
Performance over features (性能优于特性) |
||
Journaling (with --journal) is best turned on (Journaling日志功能最好打开) |
||
On 32bit systems, limited to ~2.5Gb 在32位平台MongoDB不允许数据库文件(累计总和)超过2.5G,而64位平台没有这个限制。 |
||
An empty database takes up 192Mb 空数据库大约占 192Mb |
||
GridFS to store big data + metadata (not actually an FS) 使用GridFS存储大数据和元数据(不是真正意义上的文件系统) |
GridFS是一种将大型文件存储在MongoDB的文件规范。 |
|
Values can be set to expire (as in a cache) 可以设置value过期(由于在内存中) |
expire name 10 例如:设置name这个value的过期时间是10S |
|
Simple values or hash tables by keys,but complex operations like ZREVRANGEBYSCORE.
INCR & co (good for rate limiting or statistics) |
使用简单值或以key值为索引的哈希表,也支持复杂的例如ZREVRANGEBYSCORE的有序集操作 |
|
Has sets (also union/diff/inter) Has lists (also a queue; blocking pop) Has hashes (objects of multiple fields) Sorted sets (high score table, good for range queries) |
有很多类型的数据,包括sets,lists,hash,有序集 |
|
Redis has transactions (!) |
redis支持事物处理 |
|
Pub/Sub lets one implement messaging (!) |
Pub/Sub允许用户实现消息机制,因此redis用于新浪微博中 |
|
适用——动态查询; 索引比map/reduce方式更合适时; 对于大数据库性能要求高,需要和CouchDB的功能一样,但数据变化大 |
适用——数据库大小快速变化并且总量可预测的,对内存要求高 |
|
举例——大部分用Mysql/PostgreSQL的场合,但是无法使用预先定义好所有列的时候 |
举例——股票价格、统计分析、实时数据收集、实时通信 |