原文:http://blog.nosqlfan.com/html/3729.htmlhtml
這兩年Redis火得能夠,Redis也經常被看成Memcached的挑戰者被提到桌面上來。關於Redis與Memcached的比較更是比比皆是。然而,Redis真的在功能、性能以及內存使用效率上都超越了Memcached嗎?redis
下面內容來自Redis做者在stackoverflow上的一個回答,對應的問題是《Is memcached a dinosaur in comparison to Redis?》(相比Redis,Memcached真的過期了嗎?)sql
- You should not care too much about performances. Redis is faster per core with small values, but memcached is able to use multiple cores with a single executable and TCP port without help from the client. Also memcached is faster with big values in the order of 100k. Redis recently improved a lot about big values (unstable branch) but still memcached is faster in this use case. The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver.
- 沒有必要過多的關心性能,由於兩者的性能都已經足夠高了。因爲Redis只使用單核,而Memcached可使用多核,因此在比較上,平均每一 個核上Redis在存儲小數據時比Memcached性能更高。而在100k以上的數據中,Memcached性能要高於Redis,雖然Redis最近 也在存儲大數據的性能上進行優化,可是比起Memcached,仍是稍有遜色。說了這麼多,結論是,不管你使用哪個,每秒處理請求的次數都不會成爲瓶 頸。(好比瓶頸可能會在網卡)
- You should care about memory usage. For simple key-value pairs memcached is more memory efficient. If you use Redis hashes, Redis is more memory efficient. Depends on the use case.
- 若是要說內存使用效率,使用簡單的key-value存儲的話,Memcached的內存利用率更高,而若是Redis採用hash結構來作key-value存儲,因爲其組合式的壓縮,其內存利用率會高於Memcached。固然,這和你的應用場景和數據特性有關。
- You should care about persistence and replication, two features only available in Redis. Even if your goal is to build a cache it helps that after an upgrade or a reboot your data are still there.
- 若是你對數據持久化和數據同步有所要求,那麼推薦你選擇Redis,由於這兩個特性Memcached都不具有。即便你只是但願在升級或者重啓系統後緩存數據不會丟失,選擇Redis也是明智的。
- You should care about the kind of operations you need. In Redis there are a lot of complex operations, even just considering the caching use case, you often can do a lot more in a single operation, without requiring data to be processed client side (a lot of I/O is sometimes needed). This operations are often as fast as plain GET and SET. So if you don’t need just GEt/SET but more complex things Redis can help a lot (think at timeline caching).
- 固然,最後還得說到你的具體應用需求。Redis相比Memcached來講,擁有更多的數據結構和並支持更豐富的數據操做,一般在 Memcached裏,你須要將數據拿到客戶端來進行相似的修改再set回去。這大大增長了網絡IO的次數和數據體積。在Redis中,這些複雜的操做通 常和通常的GET/SET同樣高效。因此,若是你須要緩存可以支持更復雜的結構和操做,那麼Redis會是不錯的選擇。