Redis Geo HyperLogLog Type Description

Geo type
Redis3.2.0 launched version
would be stored with the user given location information, and this information operations

GEOADD key longitude latitude member [longitude latitude member ...]
//在使用排序集表示的地理空间索引中添加一个或多个地理空间项,时间复杂度O(log(N))
127.0.0.1:6379> geoadd key1 121.3996887207031 31.04559326171875 member1 116.3883056640625 39.92889404296875 member2
(integer) 2

GEODIST key member1 member2 [unit]
//返回地理空间索引的两个成员之间的距离,时间复杂度O(log(N))
127.0.0.1:6379> geodist key1 member1 member2
"1086809.8477"//默认单位为m
127.0.0.1:6379> geodist key1 member1 member2 m
"1086809.8477"
127.0.0.1:6379> geodist key1 member1 member2 km
"1086.8098"
127.0.0.1:6379> geodist key1 member1 member2 ft
"3565649.1067"//英尺
127.0.0.1:6379> geodist key1 member1 member2 mi
"675.3140"//英里

GEOHASH key member [member ...]
//将地理空间索引的成员作为标准的geohash字符串返回,时间复杂度O(log(N))
127.0.0.1:6379> geohash key1 member1 member2
1) "wtw2de8t9v0"
2) "wx4g0kz6sj0"

GEOPOS key member [member ...]
//返回地理空间索引成员的经度和纬度,时间复杂度O(log(N))
127.0.0.1:6379> geopos key1 member1 member2
1) 1) "121.39969021081924438"
   2) "31.0455930059736076"
2) 1) "116.38830453157424927"
   2) "39.92889337816622941"

GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
//官方解释:查询表示地理空间索引的已排序集,以获取与给定的最大距离相匹配的成员
//以给定的经纬度为中心,返回给定key包含的位置元素当中,与给定的中心不超过给定最大距离的所有位置元素,时间复杂度为O(N+log(M)),N为指定半径范围内的元素个数,M为要返回的个数
//WITHDIST:在返回位置元素的同时将位置元素与中心之间的距离也一并返回,距离的单位和用户给定的范围单位保持一致
//WITHCOORD:将位置元素的经度和维度也一并返回
//WITHHASH:以52位有符号整数的形式,返回位置元素经过原始geohash编码的有序集合分值,这个选项主要用于底层应用或者调试,实际中的作用并不大
//命令默认返回未排序的位置元素。通过以下两个参数,用户可以指定被返回位置元素的排序方式:
ASC:根据中心位置,按照从近到远的方式返回位置元素
DESC:根据中心位置,按照从远到近的方式返回位置元素
//COUNT:获取前N个匹配元素
127.0.0.1:6379> geoadd key2 121.3996887207031 31.04559326171875 member1 116.3883056640625 39.92889404296875 member2 113.5325012207031 34.68359375 member3 115.9332885742188 28.55000305175781 member4
(integer) 4
127.0.0.1:6379> georadius key2 116.3883056640625 39.92889404296875 1500 km
1) "member4"
2) "member1"
3) "member3"
4) "member2"
127.0.0.1:6379> georadius key2 116.3883056640625 39.92889404296875 1500 km withcoord withdist withhash
1) 1) "member4"
   2) "1266.3179"
   3) (integer) 4051459586134239
   4) 1) "115.93328922986984253"
      2) "28.55000287189253072"
2) 1) "member1"
   2) "1086.8099"
   3) (integer) 4054751755931817
   4) 1) "121.39969021081924438"
      2) "31.0455930059736076"
3) 1) "member3"
   2) "635.6729"
   3) (integer) 4064933024035472
   4) 1) "113.53250294923782349"
      2) "34.6835946401745403"
4) 1) "member2"
   2) "0.0001"
   3) (integer) 4069885541758997
   4) 1) "116.38830453157424927"
      2) "39.92889337816622941"
127.0.0.1:6379> georadius key2 116.3883056640625 39.92889404296875 1500 km withcoord withdist withhash count 2 desc
1) 1) "member4"
   2) "1266.3179"
   3) (integer) 4051459586134239
   4) 1) "115.93328922986984253"
      2) "28.55000287189253072"
2) 1) "member1"
   2) "1086.8099"
   3) (integer) 4054751755931817
   4) 1) "121.39969021081924438"
      2) "31.0455930059736076"

GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
//官方解释:查询表示地理空间索引的已排序集,以获取与成员匹配的给定最大距离的成员
//给定距离由自定义成员变成了key中成员,时间复杂度为O(log(N)+M),N为指定半径范围内的元素个数,M为要返回的个数

HyperLogLog type
Redis2.8.9 version launch
base of redis statistics, 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. HyperLogLog each content key is occupied by 12K in Redis, a close approximation theory storing 2 ^ 64 values, no matter what the content is stored, it is a cardinality estimation algorithm based on more accurate estimate can only base, can a small amount of memory used to store a fixed and unique identification of the collection elements. And this is not necessarily accurate estimate of the base, is 0.81% with a standard error of approximation.

PFADD key element [element ...]
//将指定的元素添加到指定的HyperLogLog。

PFCOUNT key [key ...]
//返回由HyperLogLog at key观察到的集合的近似基数。

PFMERGE destkey sourcekey [sourcekey ...]
//将N个不同的HyperLogLogs合并为一个。

127.0.0.1:6379> PFADD key10 "aaa" "bbb" "ccc"
(integer) 1
127.0.0.1:6379> pfadd keys1 "aaa" "bbb" "ccc"
(integer) 1
127.0.0.1:6379> pfcount keys1
(integer) 3
127.0.0.1:6379> pfadd keys2 "bbb" "ccc" "ddd"
(integer) 1
127.0.0.1:6379> pfcount keys1 keys2
(integer) 4
127.0.0.1:6379> pfmerge keys3 keys1 keys2
OK
127.0.0.1:6379> pfcount keys3
(integer) 4

Guess you like

Origin www.cnblogs.com/JoshWill/p/11938729.html