Initial knowledge of Redis and memcached

Source: Internet
Author: User
Tags data structures hash key string memcached redis
first, the difference between Redis and memcached (first edition):1. Memcached only provides a string value type, while Redis supports data types such as hash, List, set, Sorted set, in addition to string data types. 2, memcached maximum key length 250 characters, key value maximum capacity 1mb;redis A key value pair of maximum capacity of 512MB. 3, memcached is a pure cache, all data is stored in memory, and Redis in addition to the memory cache, there are two persistence methods snapshotting snapshot and Append-only append. 4. Redis supports master-slave replication. II. data structures supported by Redis and their characteristicsKey String--redis uses a string to store the key, but the key cannot include spaces and "\ n" characters. Value string--The most commonly used data structure, a key corresponding to a string or value value, a key can be stored in the maximum 512MB (an English character or a number 1B, a Chinese character 2B), and is binary security (no special characters are escaped, The result is exactly the same as before the binary file is stored and the binary is read). So Redis can easily store images, video binaries, CSS files, or serialized objects (in PHP, you can serialize objects, or convert to JSON format to store objects, arrays, and so on). hash--easily stores structured data such as objects. The underlying implementation is a hashmap (but with fewer elements, to save memory, use Zipmap storage directly). list--is an important data structure with repeating elements, ordered queues, which can be inserted before and after the head, tail, or an element. The underlying implementation is a doubly linked list (more convenient to support reverse lookup traversal). Generally used for a number of watchlist, fan list, Message Queuing and other functions. set--collection, no repeating elements, will automatically use hash sorting, Redis provides instructions to find multiple sets of intersection, set, and difference set. The underlying implementation is a null HashMap of value. It is recommended to have more than one non-heavy data, or when there is a need for orthogonal complement, more practical, because of the non-heavy characteristics of set, it is often applied to record doing something, such as registering an account, to determine whether the user name is accounted for, or voting system, determine whether the user voted, etc. Sorted set--is a very useful data structure, an ordered set, similar to the SET function, except that the set is sorted by hash, and Sorted set needs to provide a score weight for sorting (if the publication time as score sort, Then the data can be automatically sorted by time). The underlying implementation is the HASHMAP and jump table, HashMap is used to provide fast score based on the hash to find the data, the jump table according to score order to save all the data. It is mainly used for features such as top posts.

Each data structure of the "Delete and change" Operation instructions can be found in the blog: iii. memcached and Redis application Scenarios     is generally considered as an enhanced version of "Memcached" because of its shorter time-to-Memcached,redis and more features, so redis is usually the preferred solution, but Memcached may be more advantageous in the following two scenarios: Memcached is more efficient when caching data that is read-only, such as caching HTML, CSS, and other cache cycles that do not need to be updated. When the cache system needs to expand horizontally and set up clusters, the memcached is less difficult than the Redis implementation.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.