Entity data such as user information is stored in memcached with protobufencoding, with an expiration date of one week, as MySQL's second-level cache
List data such as the user's subscription list is stored in redis, and the corresponding data is also backed up by MySQL. However, if redis cannot read it, it will not be read in MySQL again
Summary:
Redis has rich data structures and is suitable for storing sets, lists or ordered tables
Redis did not have a relatively complete distributed solution at the time, so we tried not to store large entity data (of course, as the number of users increased dramatically, we later implemented pseudo-distribution using hash keys)
memcached is relatively simple and faster than redis. It is suitable for storing entity data. However, the problem encountered at the time was that the packaging and parsing of json would become a bottleneck, so we later changed it all to json的包装和解析会成为瓶颈,所以后来我们全部换成了protobuf
When you need to support more data types besides key/value or when the stored data cannot be eliminated, it is more appropriate to use Redis. And if you just simply cache data, it is obviously more appropriate to use memcached. In other words, in comparison, redis is more suitable for storage, while memcache is more suitable for caching.
Someone on stackoverflow asked this question "Is memcached a dinosaur in comparison to Redis?", and the author of redis gave the answer (http://stackoverflow.com/questions/2873249/is-memcached-a-dinosaur-in- comparison-to-redis). Overall, the performance of both is very good, so there is no need to worry about which one has higher performance. However, the persistence and data synchronization mechanisms provided by redis are not available in memcached, so if you want persistence, you can only use redis. In addition, memcached is sufficient for simple key-value storage, but if you want to use more advanced data structures, such as hash, list, set, zset, etc., redis provides these types, which are more convenient to use.
This is how the former factory used it:
protobuf
encoding, with an expiration date of one week, as MySQL's second-level cacheSummary:
json
would become a bottleneck, so we later changed it all tojson
的包装和解析会成为瓶颈,所以后来我们全部换成了protobuf
When you need to support more data types besides key/value or when the stored data cannot be eliminated, it is more appropriate to use Redis. And if you just simply cache data, it is obviously more appropriate to use memcached. In other words, in comparison, redis is more suitable for storage, while memcache is more suitable for caching.
What is needed
频繁查询
且变化频率不是太高
is where these two are usefulSomeone on stackoverflow asked this question "Is memcached a dinosaur in comparison to Redis?", and the author of redis gave the answer (http://stackoverflow.com/questions/2873249/is-memcached-a-dinosaur-in- comparison-to-redis). Overall, the performance of both is very good, so there is no need to worry about which one has higher performance. However, the persistence and data synchronization mechanisms provided by redis are not available in memcached, so if you want persistence, you can only use redis. In addition, memcached is sufficient for simple key-value storage, but if you want to use more advanced data structures, such as hash, list, set, zset, etc., redis provides these types, which are more convenient to use.