Redis special data types

Special three data types Redis

(Why is he special? If using the type command to view, HyperLogLog and BitMap of type String, Geo is zSet type, but their original syntax and data types are out there)

1: HyperLogLog (cardinality estimator)

2: BitMap (java similar among the map as a data structure, but may be only numeric key type, value 0, only two values)

3: Geo (. Is a data structure of a zSet of GeoHash algorithm can be used to query nearby, but I personally think that this type of technology and performance is not recommended for production environments)

HyperLogLog

Supported in:

In Redis 2.8.9 release adds HyperLogLog structure.

basic concepts:

Redis HyperLogLog base is used to make statistical algorithms HyperLogLog advantage is that, when the number of input elements or very, very large volume of space required for the calculation base is always fixed, and is very small.

If PFADD into the same elements will be covered, rather than simply additive.

However, because HyperLogLog will be calculated based on the input element base, but does not store the input element itself, so HyperLogLog not like a collection that returns each element inputs.

performance:

In Redis inside each key HyperLogLog takes only 12 KB of memory, you can calculate the closest base 2 ^ 64 different elements. When this calculation and the base, the more the cost of memory elements of the set, the more contrast. Time complexity of these three operations are O (1).

application:

This structure can be very provincial statistics to various counts of memory, such as the number of registered IP, IP number of daily visits, page real-UV), the number of users online. But it also has its limitations, is only the number of statistics, and no way to know what specific content yes.

The basic syntax:

No. Command and description
1 PFADD key element [element ...]
Adds the specified element to HyperLogLog in.
2 PFCOUNT key [key ...]
back to the base of the estimate given HyperLogLog.
3 PFMERGE destkey sourcekey [sourcekey ...]
will be merged into a plurality HyperLogLog HyperLogLog

Reference: https://www.runoob.com/redis/redis-hyperloglog.html

BitMap

Supported in:

After Redis from 2.2 version adds setbit, getbit, bitcount and several other bitmap related commands.

basic concepts:

BitMap is an element to represent a value corresponding to one bit or by the state in which the key corresponding to the element itself is, in fact, also be achieved by operating the bottom of the string.

performance:

redis the bit map is confined within the 512MB, the maximum is 2 ^ 32. The bits are recommended for each of the control key, since the reading time to time complexity O (n), the larger string spending more time reading.

application

This data can be used to structure, store user online. Here only one key, then the user ID as a key, it is set to 1 if online, offline is set to zero.

The basic syntax:

No. Command and description
1 SETBIT key field value
Adds the specified element to the BitMap.
2 GETBIT key field
is returned to the value of a given bit of the BitMap field. Unassigned values are 0 and 0 is returned.
3 BITCOUNT key 
returns the total number of all the BitMap field is 1 bit field is given.

 

Geo

Supported in:

GEO characteristics Redis Redis 3.2 is available in versions

basic concepts:

This function can be given by the user's location information stored, and these information operations.

Mainly for location information stored in the user, in terms of distance, data location query function nearby.

performance:

The data is not the author personally do experiments, we can not guarantee the accuracy of the data.

Original data size mem 80%cpu qps
10000 5.5MB 26000
100000 14MB 22000
1000000 102MB 10000

Reference: https://www.codercto.com/a/89291.html

application

LBS can be used in the vicinity of inquiry, but the author is not recommended.

1: This feature can only support simple query in the vicinity, if the need arises, the various states, the type of filter. Using this function on a non-existent (eg in the vicinity within 1 km of the query with female users)

2: The function of the data storage structure is a single, more difficult to meet the moment, complex applications demand Internet applications.

(If you have a boss needs this direction, refer to the author of another article, a simple implementation of LBS for nearby queries)

(Concept above article, definitions, etc. If an error occurs Tell me please correct me)

Released three original articles · won praise 5 · Views 2624

Guess you like

Origin blog.csdn.net/qq_29889637/article/details/104293344