I was using redis during this time, and it was quite convenient, but I was wondering when to choose redis and memcache when to choose a memory database. Then I found the following information, it is from the author of redis (above stackoverflow ).
You shoshould 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 100 K. 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.
You shoshould 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.
You shoshould 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.
You shoshould 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 ).
Some netizens Translate the following [1]:
There is no need to focus too much on performance.Because redis only uses a single core, while memcached can use multiple coresTherefore, in comparison, redis has higher performance than memcached in storing small data on average per core. Memcached has higher performance than redis in data of more than kb. Although redis has recently optimized its performance in storing big data, it is inferior to memcached. The conclusion is that no matter which one you use, the number of requests processed per second will not become a bottleneck.
You need to pay attention to memory usage. For simple data storage such as key-value, memcache memory usage is higher. If the hash structure is used, redis memory usage will be higher. Of course, these depend on specific application scenarios.
You need to pay attentionWhen focusing on data persistence and master-slave Replication, OnlyRedisThese two features are available. If your goal is to build a cache without data loss after upgrade or restart, you can only choose redis.
You should be concerned about the operations you need. Redis supports many complex operations, even considering the memory usage. You can do a lot in a single operation, instead of reading data to the client (this requires a lot of Io operations ). These complex operations are basically as fast as those of pure get and post operations, so redis will play a major role when you don't just need get/set but more operations.
The choice of the two depends on the specific application scenario. If the data to be cached is a simple structure such as key-value, I still use memcache in the project, it is also stable and reliable. If you are involved in a series of complex operations such as storage and sorting, you can definitely choose redis.
For the differences between redis and memcache, the following lists some related statements for record:
The difference between redis and memecache lies in [2]:
1. Storage Method:
Memecache stores all the data in the memory. After the power is down, the data cannot exceed the memory size.
Some redis instances are stored on hard disks. This ensures data persistence and supports data persistence (Note: There are two persistence Methods: snapshot and aof log. in actual application, pay special attention to the configuration of file snapshot parameters. Otherwise, it is likely that the server is frequently loaded with dump.).
2. supported data types:
Redis has more data support than memecache.
3. Use different underlying models:
The new version of redis directly builds its own VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request.
4. Different runtime environments:
Currently, redis only supports Linux, saving support for other systems. In this way, you can focus more on the optimization of the system environment, after that, a Microsoft team wrote patches for it. But not on the trunk
In my personal summary, for applications with persistence requirements or advanced requirements for data structure and processing, select redis, other simple key/value storage, and select memcache.
Ref:
[1] http://blog.csdn.net/tonyxf121/article/details/7857635
[2] http://www.dewen.org/q/971
From http://www.cnblogs.com/EE-NovRain/p/3268476.html