The characteristics of

An unreliable, non-relational database

Provides data structure services

Method of use

The setting of the Key


incr NUM:count:pv:bac.com/a/123:2019:07:01
Copy the code

Key should have good visibility

NUM data classes

The count technology

What does PV do?

Bac.com/a/123 address

2019:07:01 time

Object storage


hmset H:cache:userinfo:105 username qer nicnamne error404 sex 1 age 18

undefined

 hgetall H:cache:userinfo:105
Copy the code

The set of Redis

  • set
  • zset
  • Message queue, which can only send character messages,

case

PV statistics


incr NUM:count:pv:bac.com/a/123:2019:07:01
Copy the code

Key should have good visibility

NUM data classes

The count technology

What does PV do?

Bac.com/a/123 address

2019:07:01 time

Use it in the Web portal

Setting things to follow in real time is a good fit for Redis,

But it’s best to pull out data every day for calibration and persistence

Month to live

The number of days in a month that each user of a piece of software uses


undefined

incr NUM:count:pv:bac.com/a/123:2019:07:01

undefined

bitcount BIT:count:MAU:guid:105:2019:07
Copy the code

Booking (Movie booking problem)

Seats are represented by bitmaps

The state of a seat is represented by a combination of different bitmaps

Daily sales statistics can also be done through Redis

Cache-triggered update mechanism

Once data is updated, it will be inserted into the database first and put into Redis after it takes effect

Check redis first and then the database

Seconds kill scenes

  • Message queue -> parallel to serial, most of the e-commerce solutions, queuing first, after processing, processing results through SSE prompts, need to build SSE, message middleware
  • In the form of list of low-cost Redis, seconds kill goods are put into the list (lpush). If someone seconds kill, pop, pop failure means seconds kill failure

Solve the problem of paging queries in high insertion scenarios

In paging queries, after clicking on the next page and inserting data, the query results may still contain old results or cause logic confusion

The solution

  • Insert data offset(count) before query (BAD)

  • Query join timestamp (BAD)

    • However, millisecond timestamps can still have a lot of data insertion and can’t be solved
  • Use caching to store their query data for each user and then paginate the query results (OK)

  • Reverse lookup (reverse output) Paging (relational database solution) (OK)

  • Redis is used to store the ID of the data to be queried [Redis is used as the index, without ES or mongodb]. The queried data is put into Redis, Rpush adds data, and Lrange takes out corresponding data. Lrang key llen-x llen (OK)