A, Bitmaps

  1. Features: Pseudo-data type, based on String implementation, maximum length of 512M, suitable for 2^32 different bytes.
  2. Common commands: SETBIT, GETBIT, BITCOUNT
Usage scenarios
  1. Bit statistics for a given range (e.g. demographics)
  2. Daily active statistics, IP login statistics.
  3. Bloom filter.
Matters needing attention
  1. Stores space-saving and high-performance Boolean information associated with object ids.
  2. If the user starts with a large id, it wastes space up front.
Realize the principle of

Bitmaps are not real data structures, but rather a collection of bit-oriented operations on strings. Because Redis keys and values are binary, Bitmaps are a unique extension of String.

Second, the HyperLogLog

  1. Features: Algorithms for radix statistics, not real data structures.
  2. Common commands are PFADD, PFCOUNT, and PFMERGE.
Usage scenarios
  1. Daily active statistics, IP statistics.
  2. Statistics APP or web page of a page, visit the situation
Matters needing attention
  1. HLL quasi error is less than 1% of the estimated metric, usually around 0.81%.
  2. HLL only calculates the cardinality from the input elements, not the input elements themselves; So HLL cannot return the input elements as collections do.
  3. Each HLL key only costs 12KB of memory at most.
Realize the principle of
  1. HLL occupies up to 12K of memory space per KEY and can calculate cardinality of close to 2^64 different elements;
  2. HLL storage space is stored by sparse matrix, which occupies very small space. Only when the number of counting base gradually increases and the space occupied by sparse matrix gradually exceeds the threshold value, it will be converted into dense matrix at one time, and it will occupy 12K memory space after converting into dense matrix.

Third, Geo

  1. Features: geographic information positioning.
  2. Common commands: GEOADD, GEOHASH, GEOPOS
Usage scenarios
  1. Real nearby people, distance calculation between two geographical locations and other functions.
Matters needing attention
  1. Supports the preservation of latitude and longitude of an object.
  2. Supports matching of points near points.
  3. Query object information based on the object ID.
Realize the principle of

The underlying implementation of Redis GEO is Zset; The GeoHash principle is simple: binary interval, interval encoding.


In the actual application development, redis advanced data type is not used much, Bitmaps to achieve the Bloom filter, HyperLogLog statistics daily live, buried points. Geo is a bit of an underdog, but There are some advantages to Geo at Elastic Search. In the case of large data volume of REDis GEO, the whole Redis query will be slow, and the maintenance cost of another cluster will be high, so ES is not needed.