Home>Article>Database> Under what circumstances do you tend to use redis?

Under what circumstances do you tend to use redis?

尚
Original
2019-07-04 13:27:53 5014browse

Under what circumstances do you tend to use redis?

When do you tend to choose redis?

1. Complex data structure

When the value is a complex data structure such as hash, list, set, ordered set, etc., it is more appropriate to choose redis, because mc cannot meet such needs.

Typical scenarios: user messages, comments, order lists, etc.

2. Persistence

mc does not support persistence

But the use of redis persistence It should be noted that

Never use redis as a database:

1) Regular snapshots of redis cannot guarantee that data will not be lost

2) The AOF of redis will reduce efficiency. And it cannot support large amounts of data

caching scenarios. What are the pros and cons of turning on persistence?

Advantages: The down machine is restarted, hotspot data can be quickly restored in the memory, and the database pressure is shared. There is no cache warm-up process.

Disadvantages: After redis hangs, the data in the database is modified, which may cause Data in redis is inconsistent

Read-only scenarios, or some business scenarios that allow inconsistencies, you can try to enable the redis persistence function

3, natural high availability

redis naturally supports clusters Function, can realize master-slave replication, read-write separation

Redis officially provides sentinel cluster management tool, which can realize master-slave service monitoring and automatic failover

Mc wants to achieve high availability, you need For secondary development

It should be noted that in most business scenarios, does the cache really need to be highly available?

1) In storage scenarios, cache miss is allowed in many cases.

2) If the cache fails, data can be read through DB in many cases.

4. The stored value is very The value storage of large

mc is up to 1m. If the stored value is very large, you can only use redis

For more Redis related knowledge, please visitRedis usage tutorialColumn!

The above is the detailed content of Under what circumstances do you tend to use redis?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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