In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is about what is the difference between redis and memcache in PHP. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
The difference between redis and memcache in PHP
Memcached and redis in PHP are very similar: both are memory databases, and the data is stored in memory and accessed directly through tcp. The advantage is high speed and high concurrency, but the disadvantage is that the data type is limited and the query function is not strong, so it is generally used as cache.
So the subject said that redis can do all the things in memcached, so why does memcached still have people using it? That's because they are not completely substitutable for each other, and they have their own strengths and weaknesses:
Memcached
Advantages of Memcached:
Memcached can take advantage of multi-cores, and the throughput of a single instance is extremely high, reaching hundreds of thousands of QPS (depending on the byte size of key and value and the hardware performance of the server, the peak QPS in daily environment is about 4-6w).
Suitable for maximum load, effectively decompress the server.
Direct configuration of session handle is supported.
There are fewer pits for configuration and maintenance.
Limitations of Memcached:
The data structure is simple and simple, and only supports simple key/value data structures, unlike Redis, which can support rich data types.
Cannot be persisted, data cannot be backed up, it can only be used for cache use, and all data is lost after restart.
Data synchronization cannot be performed and data from MC cannot be migrated to another MC instance.
Memcached memory allocation uses Slab
Allocation mechanism manages memory. When there is a large difference in value size distribution, the memory utilization will be reduced, and problems such as kicking out will still occur when the utilization is low. Users are required to pay attention to value design.
The memcached server natively does not support horizontal scaling, so the cache distribution strategy must be written on the client side to achieve distributed cache. because data synchronization cannot be carried out, the operation of some businesses may be affected when there is a stand-alone failure in the production environment.
Redis
Advantages of Redis:
Supports a variety of data structures, such as string (string),
List (two-way linked list), dict (hash table), set (collection), zset (sorted set), hyperloglog (cardinality estimation), and so on.
Support persistence operation, aof and rdb data can be persisted to disk, thus data backup or data recovery and other operations, a better means to prevent data loss.
Support data replication through Replication, through master-slave mechanism, real-time synchronous data replication, support multi-level replication and incremental replication. Master-slave mechanism is an important means for Redis to carry out HA.
Single-thread request, all commands are executed serially, and data consistency does not need to be considered in the case of concurrency.
Support pub/sub message subscription mechanism, which can be used for message subscription and notification.
Simple transaction requirements are supported, but the industry uses few scenarios and is not mature.
Limitations of Redis:
Redis can only use single thread, and its performance is limited by CPU performance, so the maximum CPU of a single instance can reach 5-6wQPS per second (depending on data structure, data size and server hardware performance, the peak of QPS in daily environment is about 1-2w).
Simple transaction requirements are supported, but the industry uses few scenarios and is immature, which is both an advantage and a disadvantage.
Redis consumes more memory on the string type, so you can use dict (hash Table) compressed storage to reduce memory consumption.
Summary
In my opinion, Redis has the characteristics of a database, or a database system, in many ways, while Memcached is just a simple Khand V cache.
And whether to use redis or memcached this or depends on the needs of the subject, because simply to do cache, memcached is enough to meet most of the needs, the emergence of redis just provides a better choice, but does not mean that redis can completely replace memcached, or that sentence, depends on what your needs are.
According to the old and new technology, redis is newer than memcached, but when it comes to maturity, memcached should be better, and now the trend has begun to switch to mongodb, because of the database characteristics of redis, mongodb is better.
Many companies still use memcached in their cache strategy, followed by redis, and finally mongodb. I found that it still takes time for the latest technology to be applied by the company team, and the old technology strategy is still used by many company teams, because the technology is shaped and stable, which is why memcached is mentioned more than redis.
Thank you for reading! So much for sharing what is the difference between redis and memcache in PHP. I hope the above content can be helpful to you so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.