Redis slow query, pipeline, publish subscribe, bitmap, hyperloglog, geo quick understanding

Time:2020-9-14

Redis slow query, pipeline, publish subscribe, bitmap, hyperloglog, geo quick understanding

Redis slow query

1. Used to view redis slow log.

Redis pipeline

1. For batch operation

Publish subscribe

1. Role: publisher and subscriber, channel.
2. Model: similar to producer and consumer.
3.API

  • publish: publish channel message
  • subscribe: subscribe channel
  • unsubscribe: unsubscribe channel
  • Psubscribe: mode subscription.
  • Punsubscribe: unsubscribe from the specified mode.
  • PubSub channels: lists channels with at least one subscriber.
  • PubSub numsub: lists the number of subscribers for a given channel.
  • PubSub numpat: lists the number of subscribed modes.

4. The difference between message queue and message queue: only one subscriber of message queue can receive it, while both publish and subscribe can receive it.

Bitmap

1. Setbit key offset value: Specifies the index setting value for the bitmap.
2. Do not set a large offset on a short key.
3. Getbit key offset gets the value of the specified offset.
4. Bitcount: gets the number of bitmaps with the specified range bit value of 1.
5. Bitop: do multiple bitmap and or not XOR operations and save the results to destkey.
6. Bitpos: computes the position where the first offset of the bitmap is equal to the targetbit.
710 million users and 50 million independent users

data type Per user_ ID takes up space Number of users to store All memory
set 32 bit 50000000 32 bit * 50000000 = 200MB
bitmap 1 100000000 32 bit * 100000000 = 12.5mb

However, small independent users such as (100000) are better to use set because of the 100 million user data that is required by bitmap.

8. Bitmap is a string type, with a maximum of 512M.
9. Pay attention to the offset of setbit, which may consume more time.
10. Bitmap is not absolutely good.

HyperLogLog

1. Complete the statistics of independent users in very small space.
2. The essence is string.
3. Pfadd key element: add an element to the hyperloglog.
4. Pfcount key: calculate the independent total.
5. Pfmerge destket sourcekey1 sourcekey2: merge.
6. The error rate was 0.81%.
7. Unable to retrieve single data.

GEO

1. Store longitude and latitude to calculate geographic location information.
2. Scene: shake.
3. Geo key longitude latitude member stores longitude and latitude.
4. Geopos key member obtains latitude and longitude.
5. Geodist key member1 member2 unit to obtain the distance between two geographical locations.
6. Geodius obtains the geographic location information set within the specified location range.
Only 7.3.2 + can be implemented with Zset.