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

相比來看,CouchDB 的長處正是Redis的短處:存儲大量的不易變但會被經(jīng)常查詢的數(shù)據(jù)。Redis的長處正是CouchDB的短處:存儲小量的常變數(shù)據(jù)。
以一個博客系統(tǒng)為例,CouchDB作為一個文檔型數(shù)據(jù)庫,可以用來存儲文章,評論,模板及附件等,而Redis以其豐富的數(shù)據(jù)類型的數(shù)據(jù)結(jié)構(gòu),更適合用來存儲評論列表,網(wǎng)站實時狀態(tài),過濾spam,用戶session信息以及頁面緩存。
作為一個內(nèi)存數(shù)據(jù)庫,Redis提供了快速對其數(shù)據(jù)結(jié)構(gòu)進行復(fù)雜操作的功能,另外通過一份順序的日志來保證其數(shù)據(jù)可靠性。
CouchDB使用了一種append-only的數(shù)據(jù)模型,不僅在數(shù)據(jù)庫數(shù)據(jù)存儲上,包括其B-tree和R-tree索引都是append-only的,所以如果你的數(shù)據(jù)修改操作太多(比如計數(shù)器應(yīng)用),那么CouchDB的數(shù)據(jù)文件會飛速膨脹。
Redis采用定時將內(nèi)存數(shù)據(jù)Flush成RDB文件的方法來實現(xiàn)數(shù)據(jù)的持久化,而CouchDB的數(shù)據(jù)需要定時做數(shù)據(jù)壓縮以縮減數(shù)據(jù)文件的大小,這一過程會把數(shù)據(jù)文件讀入,壓縮后再寫成新的文件。是一個非常耗時的過程。
Redis提供了簡單的索引機制和復(fù)雜的數(shù)據(jù)結(jié)構(gòu),而CouchDB提供的是復(fù)雜的索引和簡單的數(shù)據(jù)結(jié)構(gòu)。Redis適合用來存儲實時數(shù)據(jù),而CouchDB適合用來存儲大量的文檔型數(shù)據(jù)。
下面是一個更詳細的各方面對比表格:
| 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