Three special data types

Geospatial

  • Effective longitude ranges from -180 degrees to 180 degrees.
  • Valid latitudes range from -85.05112878 degrees to 85.05112878 degrees.

Geoadd adds the geographic location coordinates of the city

  • You can add multiple at a time
Geoadd key longitude latitude member...Copy the code

Geopos obtains the coordinates of the geographical location of cities.

  • You can get more than one at a time
Geopos Key Member...Copy the code

Geodist calculates the distance between two locations.

  • M: meter, the default unit.
  • Km: km.
  • Mi: Miles.
  • Ft: Feet.
Geodist Key Member1 Member2 km/m/mi/ftCopy the code

Georadius obtains a set of geographical locations within a specified range according to latitude and longitude coordinates.

Longitudus key latitude km/m/mi/ftCopy the code

Georadiusbymember retrieves a geographic location set within a specified range based on a location stored in the location set.

Km /m/mi/ft (unit)Copy the code

Geohash Returns the geohash value of one or more positional objects.

georadiusbymember key member1 member2....
Copy the code

The test case

127.0.0.1:6379> geoadd China :city 88.31104 43.36378 wulumuqi# Add location of Urumqi
(integer) 1 127.0.0.1:6379> GeoAdd China: City 116.23128 40.22077 Beijing# Add location of Beijing
(integer) 1 127.0.0.1:6379> Geoadd China: City 106.54041 29.40268 CHONGQING# Add location of Chongqing
(integer) 1 127.0.0.1:6379> GeoAdd China: City 126.95717 45.54774 haerbin# Add Harbin location
(integer) 1 127.0.0.1:6379> Geoadd China: City 117.20767 39.077969 tianjin# Add tianjin location
(integer) 1 127.0.0.1:6379> Geopos China: City haerbinGet the location of Harbin
1) 1) "126.95716828107833862"
   2) "45.54773904285200103"127.0.0.1:6379> geopos China: City Haerbin ChongqingGet the location of Harbin and Chongqing
1) 1) "126.95716828107833862"
   2) "45.54773904285200103"
2) 1) "106.54040783643722534"
   2) "29.40268053517299762"127.0.0.1:6379> Geodist China: City Haerbin ChongqingGet the distance from Harbin to Chongqing in m
"2529857.4392"127.0.0.1:6379> Geodist China: City Haerbin Chongqing KMGet the distance from Harbin to Chongqing in km
"2529.8574"127.0.0.1:6379> Georadius China: City 110 30 30 km# get cities within (110,30) 30km of latitude and longitude(Empty array) 127.0.0.1:6379> Georadius China: City 110 30 100 km# get cities within (110,30) 50km of latitude and longitude(Empty array) 127.0.0.1:6379> Georadius China: City 110 30 500 km# get cities within (110,30) 500km of latitude and longitude
1) "chongqing"127.0.0.1:6379> Georadius China: City 110 30 500 km withcoordGet the city within (110,30) 500km and return its latitude and longitude
1) 1) "chongqing"
   2) 1) "106.54040783643722534"
      2) "29.40268053517299762"127.0.0.1:6379> Georadius China: City 110 30 500 km withCoord withdistGet the city within (110,30) 500km and return its latitude and longitude and the distance between (110,30)
1) 1) "chongqing"
   2) "340.7667"
   3) 1) "106.54040783643722534"
      2) "29.40268053517299762"127.0.0.1:6379> Georadiusbymember China: City Beijing 500 km withdist withcoordGet the cities within 500km of Beijing, and give the distance, latitude and longitude
1) 1) "tianjin"
   2) "152.1447"
   3) 1) "117.20767110586166382"
      2) "39.07796974192802253"
2) 1) "beijing"
   2) "0.0000"
   3) 1) "116.23128265142440796"
      2) "40.22076905438526495"127.0.0.1:6379> GeoHash China: City Wulumuqi Chongqing tianjin# Get the geohash value of urumqi, Chongqing and Tianjin
1) "tzwy9w4hk60"
2) "wm5z22s7520"
3) "wwgq71uj8t0"
Copy the code

Hyperloglog

Introduction to the

  1. Redis is used to do cardinality statistics data structure algorithm
  2. It takes up only 12KB of memory
  3. Allowable statistical error
  • Cardinality: The total number of distinct numbers in the sets A and B

Pfadd creates the elements of the collection

pfadd key value1 value2 ....
Copy the code

Pfcount The number of cardinals in the collection

pfcount key
Copy the code

Pfmerge Merges collections

# merge key1 key2.. To the key
pfmerge key key1 key2 .... 
Copy the code

The test case

127.0.0.1:6379> pfadd hykey1 a b c d e f g h Create the first collection
(integer) 1
127.0.0.1:6379> pfcount hykey1 # Count the cardinality of the first set
(integer) 8
127.0.0.1:6379> pfadd hykey2 g h i j k l m n o p q Create a second collection
(integer) 1
127.0.0.1:6379> pfcount hykey2 # Count the cardinality of the second set
(integer) 11
127.0.0.1:6379> pfmerge hykey hykey1 hykey2 # merge hykey1 hykey2 to hykeyOK 127.0.0.1:6379 > pfcount hykey# Count the cardinality of the combined set
(integer6379 > 17 127.0.0.1) :Copy the code

Bitmap

Introduction to the

  1. Bitmap for bit storage
  2. It only stores two states, for example, late check-in, only signed and unsigned (0, 1).

Setbit stores data

setbit key member 0/1
Copy the code

Getbit reads the state of the data

getbit key member 
Copy the code

Bitcount statistics (state 1 data)

bitcount key 0/1
Copy the code

The test case

127.0.0.1:6379> setbit bp1 1 1 1# Store data
(integer) 0
127.0.0.1:6379> setbit bp1 2 1
(integer) 0
127.0.0.1:6379> setbit bp1 3 0
(integer) 0
127.0.0.1:6379> setbit bp1 4 1
(integer) 0
127.0.0.1:6379> setbit bp1 5 1
(integer) 0
127.0.0.1:6379> setbit bp1 6 0
(integer) 0
127.0.0.1:6379> setbit bp1 7 0
(integer) 0
127.0.0.1:6379> getbit bp1 5  Read the state of data
(integer) 1
127.0.0.1:6379> getbit bp1 6
(integer) 0
127.0.0.1:6379> bitcount bp1 # Number of reads in state 1
(integer4)Copy the code