Home >Database >Redis >How to use redis in projects

How to use redis in projects

(*-*)浩
(*-*)浩Original
2019-11-21 14:23:044288browse

Redis, as an in-memory database with excellent performance, has a variety of application scenarios in Internet companies. This article introduces the scenarios in which the author uses Redis in projects.

How to use redis in projects

Mainly introduced from the following aspects:

Distributed locks (Recommended learning: Redis video Tutorial)

Interface current limiter

Order cache

Redis and DB data consistency processing

Prevent cache penetration and avalanche

Distributed session sharing

Order cache

The storage structure of the entire order is as follows:

How to use redis in projects

Use Redis's zset data structure to store each user's orders, arranged in reverse order by order time, with the user's unique identifier as the key, the user's order collection as the value, and the last three digits of the order number as the timestamp of the order creation time as the score

Why not just use the timestamp of the order time as the score? Because the order time is only accurate to the second, multiple orders may appear in the same second, so the same score will appear. Adding the last three digits of the order number can basically avoid this situation.

Only put the user’s first N orders, because few users will view orders from long ago, so this will save a lot of space. If a user needs to check the orders after the first N orders, they can query them from the database. Of course, the probability of this is relatively small.

The above is the detailed content of How to use redis in projects. 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