Table of Contents
Reply content:
Brief description
Memcached
Redis
Summary
Home Backend Development PHP Tutorial What is the difference between Redis and Memcached?

What is the difference between Redis and Memcached?

Jul 06, 2016 pm 01:51 PM
memcached php redis middleware cache

Redis also has key-value pair storage, which can also be stored in memory, and also supports persistent storage. Moreover, redis clusters, distributed deployment, and mirror synchronization are all natively supported, which is more convenient than memcached (memcached requires its own It is very troublesome to write a consistent hash algorithm to determine which memcached node the value corresponding to a certain key is stored on.) So what is the use of memcached?
Why not just use redis instead of memcache?
(I think there are still many PHP tutorials, the textbooks all talk about memcached, and there are still relatively few mentions of redis. I only found out about such a thing by reading other people's blogs.)

Reply content:

Redis also has key-value pair storage, which can also be stored in memory, and also supports persistent storage. Moreover, redis clusters, distributed deployment, and mirror synchronization are all natively supported, which is more convenient than memcached (memcached requires its own It is very troublesome to write a consistent hash algorithm to determine which memcached node the value corresponding to a certain key is stored on.) So what is the use of memcached?
Why not just use redis instead of memcache?
(I think there are still many PHP tutorials, the textbooks all talk about memcached, and there are still relatively few mentions of redis. I only found out about such a thing by reading other people's blogs.)

It depends!

  • Memcached is a multi-threaded non-blocking IO reuse network model; Redis uses a single-threaded IO reuse model

  • MemcachedUse a pre-allocated memory pool; RedisUse on-site memory application to store data

  • The servers of
  • Memcached are completely independent of each other; Redisplans to build support for clustering into the server

  • MemcachedCan use multiple cores; RedisOnly single core

In short, if you use simple key-value storage, Memcached has higher memory utilization. When you need support for more data types other than key/value, it is more appropriate to use Redis. Hope it helps you

Redis is replacing Memcached, but you have to know that Redis is a new thing. For a huge system, it will take time to completely replace it.
Currently Weibo uses Redis cluster.

Thanks for the invitation~~

I was out and about without internet connection before. Now I will give you some of my personal opinions and some reference materials. If you find it useful, please take it. If you make any mistakes, you are welcome to support me. If you think it is good, please give it a thumbs up~~~

First of all, let me explain a point: existence is reasonable, and some people use it to prove that it has its own value.

Brief description

Memcached and redis are very similar: they are both in-memory databases. Data is stored in memory and directly accessed through tcp. The advantages are fast speed and high concurrency. The disadvantages are limited data types and weak query functions. They are generally used for cache.

So the questioner said that redis can do all the things memcached does, so why do people still use memcached? That’s because the two of them are not completely interchangeable. They also have their own strengths and weaknesses:

Memcached

Advantages of Memcached:

  • Memcached can take advantage of multi-core, and the throughput of a single instance is extremely high, which can reach hundreds of thousands of QPS (depending on the byte size of key and value and the performance of the server hardware, the peak QPS in daily environment is about 4-6w about).

  • Suitable for maximum load capacity and effectively decompressing the server.

  • Supports direct configuration as session handle.

  • There are relatively few pitfalls in configuration and maintenance.

Limitations of Memcached:

  • The data structure is very simple and single, and only supports simple key/value data structures, unlike Redis which can support rich data types.

  • Unable to be persisted, data cannot be backed up and can only be used for caching, and all data will be lost after restarting.

  • Data synchronization cannot be performed, and data in MC cannot be migrated to other MC instances.

  • Memcached memory allocation uses the Slab
    Allocation mechanism to manage memory. Large differences in value size distribution will cause memory utilization to decrease, and cause problems such as kicking out even when utilization is low. Users need to pay attention to value design.

  • The memcached server does not natively support horizontal expansion. A cache distribution strategy must be written on the client to implement distributed caching. Since data synchronization cannot be performed, a single machine failure in the production environment may affect some business operations. .

Redis

Advantages of Redis:

  • supports a variety of data structures, such as string (string),
    list (double linked list), dict (hash table), set (set), zset (sorted set), hyperloglog (cardinality estimation) etc.

  • Supports persistence operations, and can persist aof and rdb data to disk for data backup or data recovery, which is a better way to prevent data loss.

  • Supports data replication through Replication. Through the master-slave mechanism, data can be replicated synchronously in real time. It supports multi-level replication and incremental replication. The master-slave mechanism is an important means for Redis to perform HA.

  • Single-threaded request, all commands are executed serially, and there is no need to consider data consistency issues in concurrent situations.

  • Supports pub/sub message subscription mechanism, which can be used for message subscription and notification.

  • Supports simple transaction requirements, but there are few use cases in the industry and it is not mature.

Limitations of Redis:

  • Redis can only use a single thread, and its performance is limited by CPU performance. Therefore, a single instance CPU can only reach a maximum of 5-6wQPS per second (depending on the data structure, data size and server hardware performance. QPS in daily environment The peak is around 1-2w).

  • Supports simple transaction requirements, but there are few usage scenarios in the industry and it is not mature, which has both advantages and disadvantages.

  • Redis consumes more memory for string types. You can use dict (hash table) to compress storage to reduce memory consumption.

Summary

In my opinion, Redis has the characteristics of a database in many aspects, or it is a database system, while Memcached is just a simple K/V cache.

And whether to use redis or memcached depends on the needs of the subject, because if it is just caching, memcached is enough to meet most needs. The emergence of redis only provides a better choice, but it does not mean that Redis can completely replace memcached. Again, it depends on your needs.

In terms of technology, redis is still newer than memcached, but when people mature, they say that memcached should be better. Moreover, the trend is now starting to switch to mongodb. Because of the database characteristics of redis, mongodb is superior.

Memcached still accounts for the majority of the caching strategies of many companies, followed by redis, and finally mongodb. I found that there is no such thing. It still takes time for the latest technology to be applied by the company team, and there are still many old technical strategies. The company team is using it because the technology is mature and more stable. This is why memcached is mentioned more than redis.

Look at demand, look at mastery

In fact, the performance of the two is similar, but the performance of redis is slightly better.
Redis replacing memcached is the trend.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles