Geospatial

use

The title
geoadd Adds the given space element (latitude, longitude, name) to the specified key. The data is stored in the keys as an ordered collection, allowing commands like GEORADIUS and GEORADIUSBYMEMBER to retrieve the elements later through location queries. The GEOADD command takes arguments in standard X, Y format, so the userYou must enter longitude first, then latitude.
geodist Returns the distance between two given positions. If one of the two positions does not exist, the command returns a null value. Specify the unit argumentIt must be one of the following units: m indicates that the unit is meters. Km is expressed in kilometers. Mi means miles. Ft is in feet. If the user does not explicitly specify a unit parameter, then GEODISTThe default unit is meters. The GEODIST command calculates distances by assuming that the Earth is perfectly spherical, an assumption that results in an error of up to 0.5% in extreme cases.
georadius Returns all of the location elements contained by the key that are within a given maximum distance from the center, centered at a given latitude and longitude.
georadiusbymember This command, like the GEORADIUS command, can find the elements in the specified range, but the center point of GEORADIUSBYMEMBER is determined by the given location element, instead of using the longitude and latitude of input to determine the center point, as GEORADIUS did.
geohash Returns a Geohash representation of one or more positional elements.
127.0.0.1:6379> geoadd USA 13.361389 38.115556 "New York" 15.087269 37.502669 "Texas"  # add location collection
(integer) 2
127.0.0.1:6379> geopos USA Texas  # select latitude and longitude from location
1) 1) "15.08726745843887329"
   2) "37.50266842333162032"127.0.0.1:6379 > geodist USA"New York" Texas km  # query the distance between two cities
"166.2742"
127.0.0.1:6379> georadius USA 12 37 300 km      Select a location within the specified radius of a point
1) "New York"
2) "Texas"
127.0.0.1:6379> georadius USA 12 37 200 km
1) "New York"
127.0.0.1:6379> georadius USA 12 37 300 km withdist  # The distance and place to a point within a radius
1) 1) "New York"
   2) "172.6365"
2) 1) "Texas"
   2) "278.9760"
127.0.0.1:6379> georadius USA 12 37 300 km withcoord    # Latitude and longitude within a radius to a point
1) 1) "New York"
   2) 1) "13.36138933897018433"
      2) "38.11555639549629859"
2) 1) "Texas"
   2) 1) "15.08726745843887329"
      2) "37.50266842333162032"
127.0.0.1:6379> georadius USA 12 37 300 km withcoord withdist count 1  # a place within a certain radius
1) 1) "New York"   # display only one of them
   2) "172.6365"    # Distance to a point
   3) 1) "13.36138933897018433"    # latitude and longitude
      2) "38.11555639549629859"
127.0.0.1:6379> georadius USA 12 37 300 km withcoord withdist count 2
1) 1) "New York"    
   2) "172.6365"               # withdist
   3) 1) "13.36138933897018433"   # withcoord
      2) "38.11555639549629859"
2) 1) "Texas"
   2) "278.9760"
   3) 1) "15.08726745843887329"
      2) "37.50266842333162032"
127.0.0.1:6379> georadiusbymember USA Texas 180 km  What sites are within the designated area of a site, including itself
1) "New York"
2) "Texas"127.0.0.1:6379 > geohash USA"New York"  
1) "sqc8b49rny0"
Copy the code

HyperLogLog

  • Using less memory to count something without knowing its contents

usage

The title
pfadd Adds any number of elements to the specified HyperLogLog.
pfcount When PFCOUNT key [key…] The HyperLogLog command, when applied to a single key, returns the approximate cardinality of the HyperLogLog stored in the given key, or 0 if no key exists. When PFCOUNT key [key…] When applied to multiple keys, the command returns the approximate cardinality of the union of all given Hyperloglogs by merging all given Hyperloglogs into oneTemporary HyperLogLog to calculate.
pfmerge Merge multiple Hyperloglogs into one HyperLogLog, the cardinality of the merged HyperLogLogClose to theUnion of all input Visible set of HyperLogLog.
127.0.0.1:6379> pfadd mykey a b c d e f   # create add
(integer) 1
127.0.0.1:6379> pfcount mykey     # statistics
(integer) 6
127.0.0.1:6379> pfcount mykey4 e f g h i j k k  # count the number of different elements
(integer) 7
127.0.0.1:6379> pfadd mykey2 e f g h i j k
(integer) 1
127.0.0.1:6379> pfcount mykey2   
(integer) 7
127.0.0.1:6379> pfmerge mykey3 mykey mykey2   # merge the last two different elements into myKey3OK 127.0.0.1:6379 > pfcount mykey3There are 11 abcdefghijk
(integer11)Copy the code

Bitmap

  • There are only two states that are great to use

Break down

Offset = offset

  • The offset argument must be greater than or equal to 0 and less than 2^32 (the bit mapping is limited to 512 MB).

use

The title
setbit Sets or clears the bits at the specified offset for the string value held by key. Bits can be set or cleared depending on the value argument, which can be 0 or 1. Automatically generates a new string value when key does not exist.
bitcount Counts the number of bits set to 1 in the given string. In general, the entire string given is counted, and by specifying an extra start or end argument,The units of start and end are 8 bits per byte. You can make counting happen only at certain bits.
127.0.0.1:6379> setbit bitmaps 0 1  
(integer0 127.0.0.1:6379> setbit bitmaps 1 1 (integer0 127.0.0.1:6379> setbit bitmaps 2 1 (integer0 127.0.0.1:6379> setbit bitmaps 3 1 (integer0 127.0.0.1:6379> setbit bitmaps 4 1 (integer0 127.0.0.1:6379> setbit bitmaps 5 0 (integer0 127.0.0.1:6379> setbit bitmaps 6 0 (integer0 127.0.0.1:6379> setbit bitmaps 7 0 (integer0 127.0.0.1:6379> bitcount bitmaps (integer) 5
127.0.0.1:6379> bitcount bitmaps 0 1  # only uses 8 bits, not more than one byte, so 5
(integer5)Copy the code