Session stored in Redis and saved to memcache which is better?

Source: Internet
Author: User
Tags php session
Who can synthesize the evaluation under the disadvantage, if can provide the relevant information is better.
For example, under what circumstances is it appropriate to have memcache, and under what conditions is Redis?

Reply content:

Who can synthesize the evaluation under the disadvantage, if can provide the relevant information is better.
For example, under what circumstances is it appropriate to have memcache, and under what conditions is Redis?

Well, I'm not here to answer the question. I'm from a ruined image ... Just let it be.

Although Memcache and Redis are often compared to ... But actually these two are not the same kind ...

Memcache ... It's a cache. and Redis ... It's a database ...

And for this question ... In my limited knowledge range and one-sided practical observation ... My answer is ...

ideal for storage in memcache when pursuing extreme perfection and simple application logic ... The rest of the situation is suitable for storage in Redis ...

More specifically, ... It is in the case of 99.99% that the PHP session is suitable for the existence of Redis ...

Well, I know the answer hurts. More answers are welcome to offer different opinions ...

As the first batch of people who use memcache in China ... After I used Redis, I basically gave up memcache ...

Memcache is not useless ... It's compared to the current Redis ... The only advantage ... Is fast ...

Same environment under same load same k/v structure data ...

When a single data is relatively small ... Whether it's reading or writing ... memcache is always dozens of μs faster than Redis ...

Although the gap is negligible, Redis has never won ...

If you care very very much about this point of time gap ... Well... You have the potential to be 0.01% ... But not yet.

Now look at your application scenario ... Want to be that 0.01% ... You can only store one unit in your session ...

For example, only the user name is stored to obtain a key to the username of the corresponding ... Instead of an array ...

Because both Serialize/set and get/unserialize are slower than Hset and hget ...

Before we managed to win dozens of μs ... The result was so wasted ...

If you can do this architecture ... 0.01% the door of the club is opening for you ...

But wait ... Throw away performance ... Imagine two more scenarios ...

Scene One ... If the machine that stored the session is restarted ...

The consequence of using memcache is ... All users must re-get session ... Instantaneous database pressure will be very large ...

And Redis wouldn't ... At best, it's just missing the session that hasn't been saved yet ...

Scene two ... If the sudden influx of large numbers of users generated a lot of data to store the session of the machine memory is full ...

Memcache will strike ... All keys do not expire and then overwrite the last written data ...

And Redis just slows down ... Does not affect the logic of the program ...

If you confirm that none of this will happen ... Welcome to Memcache to meet your quest for the ultimate in perfection efficiency ...

Basically, I'm still using Memcache to store the session. As far as I know, there are only two categories of people ...

The first category is for the pursuit of perfection and dazzling skills ... That's 0.01%.

The second type is pedantry or the code is too complex to be replaced ...

If you don't belong to these two categories of people ... Welcome to the mainstream Redis ...

This is basically the case ... And I don't know how much I wrote.

This topic is actually not very good answer ... To expand the words can expand to super large ... Save as a paper ...

I just want to know where to write ... Some points can be thought of but implemented into the text and do not know how to describe ...

such as memory management ... The application of multi-core CPU is distributed ...

The more you think, the less clear you will be. The wording may be a bit messy ... Will look at ...

Anyway, I came from a ruined image ... Welcome Memcache party to fight ...

For a single k-v cache, Memcache is the best choice, and its benefits lie in its simplicity and its very good speed.

However, if you need to store mappings or fields, or if you want to store a fixed-sequence table or a sortable collection, then Redis is the most appropriate.

I personally think that Redis is still a lot of lack of db, at least in terms of data persistence is not perfect. So, like Redis and Memcache, the main application scenario is in the cache.

If you just do the session storage, I personally recommend using memcached, speed is faster and easy to apply, but if you need to do something persistent you still go to use Redis. My suggestion is that when you design the system, the two blocks of the interface are reserved and can be switched at any time.

  • 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: info-contact@alibabacloud.com 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.