本文是一篇轉載翻譯文章,原文標題是 Is CouchDB The Anti-Redis? 作者在對比了Redis和CouchDB之后得出這樣一個結論,這兩家伙是反著來的,當然,這個反著來沒有對和錯,只是適合的應用場景不同,本人覺得其評價還是比較中肯,下面是對其主要內容的摘錄和翻譯,希望對你有用。

相比來看,CouchDB 的長處正是Redis的短處:存儲大量的不易變但會被經常查詢的數據。Redis的長處正是CouchDB的短處:存儲小量的常變數據。
以一個博客系統為例,CouchDB作為一個文檔型數據庫,可以用來存儲文章,評論,模板及附件等,而Redis以其豐富的數據類型的數據結構,更適合用來存儲評論列表,網站實時狀態,過濾spam,用戶session信息以及頁面緩存。
作為一個內存數據庫,Redis提供了快速對其數據結構進行復雜操作的功能,另外通過一份順序的日志來保證其數據可靠性。
CouchDB使用了一種append-only的數據模型,不僅在數據庫數據存儲上,包括其B-tree和R-tree索引都是append-only的,所以如果你的數據修改操作太多(比如計數器應用),那么CouchDB的數據文件會飛速膨脹。
Redis采用定時將內存數據Flush成RDB文件的方法來實現數據的持久化,而CouchDB的數據需要定時做數據壓縮以縮減數據文件的大小,這一過程會把數據文件讀入,壓縮后再寫成新的文件。是一個非常耗時的過程。
Redis提供了簡單的索引機制和復雜的數據結構,而CouchDB提供的是復雜的索引和簡單的數據結構。Redis適合用來存儲實時數據,而CouchDB適合用來存儲大量的文檔型數據。
下面是一個更詳細的各方面對比表格:
| Couchdb | Redis |
Written in | Erlang | C |
License | Apache | BSD |
Release | 1.1.0, 2.0 preview | 2.2.12, 2.4.0RC5 |
API | REST | Telnet-style |
API Speed | Slow | Fast |
Data | JSON documents, binary attachments | Text, binary, hash, list, set, sorted set |
Indexes | B-tree, R-tree, Full-text (with Lucene), any combination of data types via map/reduce | Hash only |
Queries | Predefined view/list/show model, ad-hoc queries require table scans | Individual keys |
Storage | Append-only on disk | In-memory, append-only log |
Updates | MVCC | In-place |
Transactions | Yes, all-or-nothing batches | Yes, with conditional commands |
Compaction | File rewrite | Snapshot |
Threading | Many threads | Single-threaded, forks for snapshots |
Multi-Core | Yes | No |
Memory | Tiny | Large (all data) |
SSD-Friendly | Yes | Yes |
Robust | Yes | Yes |
Backup | Just copy the files | Just copy the files |
Replication | Master-master, automatic | Master-slave, automatic |
Scaling | Clustering (BigCouch) | Clustering (Redis cluster*) |
Scripting | JavaScript, Erlang, others via plugin | Lua* |
Files | One per database | One per database |
Virtual Files | Attachments | No |
Other | Changes feed, Standalone applications | Pub/Sub, Key expiry |
來源:ai.mee.nu