search

Home  >  Q&A  >  body text

什么样的场景下需要同时使用Redis和Memcached?

如题,见过一些工程同时使用Redis和Memcached,感觉这样很麻烦。
如果不是早期使用Memcached且难以移植到Redis,还有没有其他可能性?

天蓬老师天蓬老师2798 days ago703

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-04-22 09:01:06

    This is how the former factory used it:

    • 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

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-22 09:01:06

    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.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-22 09:01:06

    What is needed频繁查询变化频率不是太高 is where these two are useful

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-22 09:01:06

    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.

    reply
    0
  • Cancelreply