Updated on 2024-01-23 GMT+08:00

Application Scenarios

Redis Application Scenarios

Many large-scale e-commerce websites and video streaming and gaming applications require fast access to large amounts of data that has simple data structures and does not need frequent join queries. In such scenarios, you can use Redis to achieve fast yet inexpensive access to data. Redis enables you to retrieve data from in-memory data stores instead of relying entirely on slower disk-based databases. In addition, you no longer need to perform additional management tasks. These features make Redis an important supplement to traditional disk-based databases and a basic service essential for Internet applications receiving high-concurrency access.

Typical application scenarios of DCS for Redis are as follows:

  1. E-commerce flash sales

    E-commerce product catalogue, deals, and flash sales data can be cached to Redis.

    For example, the high-concurrency data access in flash sales can be hardly handled by traditional relational databases. It requires the hardware to have higher configuration such as disk I/O. By contrast, Redis supports 100,000 QPS per node and allows you to implement locking using simple commands such as SET, GET, DEL, and RPUSH to handle flash sales.

    For details about locking, see Implementing Distributed Locks with Redis in Best Practices.

  2. Live video commenting

    In live streaming, online user, gift ranking, and bullet comment data can be stored as sorted sets in Redis.

    For example, bullet comments can be returned using the ZREVRANGEBYSCORE command. The ZPOPMAX and ZPOPMIN commands in Redis 5.0 can further facilitate message processing.

  3. Game leaderboard

    In online gaming, the highest ranking players are displayed and updated in real time. The leaderboard ranking can be stored as sorted sets, which are easy to use with up to 20 commands.

    For details, see Ranking with Redis in Best Practices.

  4. Social networking comments

    In web applications, queries of post comments often involve sorting by time in descending order. As comments pile up, sorting becomes less efficient.

    By using lists in Redis, a preset number of comments can be returned from the cache, rather than from disk, easing the load off the database and accelerating application responses.

Memcached (Discontinued) Application Scenarios

Memcached is suitable for storing simple key-value data.

  1. Web pages

    Caching static data such as HTML pages, Cascading Style Sheets (CSS), and images to DCS Memcached instances improves access performance of web pages.

  2. Frontend database

    In dynamic systems such as social networking and blogging sites, write operations are far fewer than read operations such as querying users, friends, and articles. To ease the database load and improve performance, the following data can be cached to Memcached:

    • Frequently accessed data that does not require real-time updates and can expire automatically

      Example: latest article lists and rankings. Although data is generated constantly, its impact on user experience is limited. Such data can be cached for a preset period of time and accessed from the database after this period. If web page editors want to view the latest ranking, a cache clearing or refreshing policy can be configured.

    • Frequently accessed data that requires real-time updates

      Example: friend lists, article lists, and reading records. Such data can be cached to Memcached first, and then updated whenever changes (adding, modifying, and deleting data) occur.

  3. Flash sales

    It is difficult for traditional databases to write an order placement operation during flash sales into the database, modify the inventory data, and ensure transaction consistency while ensuring uninterrupted user experience.

    Memcached incr and decr commands can be used to store inventory information and complete order placement in memory. Once an order is submitted, an order number is generated. Then, the order can be paid.

Scenarios where Memcached is not suitable:

  • The size of a single cache object is larger than 1 MB.

    Memcached cannot cache an object larger than 1 MB. In such cases, use Redis.

  • The key contains more than 250 characters.

    To use Memcached in such a scenario, you can generate an MD5 hash for the key and cache the hash instead.

  • High data reliability is required.

    Open-source Memcached does not provide data replication, backup, and migration, so data persistence is not supported.

    Master/Standby DCS Memcached instances support data persistence. For more information, contact technical support.

  • Complex data structures and processing are required.

    Memcached supports only simple key-value pairs, and does not support complex data structures such as lists and sets, or complex operations such as sorting.