geospatial
這個功能可以將用戶給定的地理位置信息儲存起來, 並對這些信息進行操作
GEO 的數據結構總共有六個命令
- geoadd
- geopos
- geodist
- georadius
- georadiusbymember
- geohash
增加一個定位:
geoadd china:city 116.40 39.90 beijing
geoadd china:city 106.50 29.53 chongqing
獲取當前定位:
deopos china:city beijing
兩個定位之間的距離:
單位:
- m標識單位爲米
- km標識單位爲千米
- mi標識單位爲英里
- ft標識單位爲英尺
geodist china:city beijing chongqing km
查詢指定半徑中的數據:
georadius china:city 100 30 1000 km #以經度100,緯度30 半徑1000km的內的城市
georadius china:city 100 30 1000 km withdist #顯示到中心位置的距離
georadius china:city 100 30 1000 km withcoord #顯示符合條件的定位
georadius china:city 100 30 1000 km withcoord count 1 #輸出指定個數符合條件的
Hyperloglog
Hyperloglog基數統計的算法。不過會有些許誤差,如果允許容錯,使用Hyperloglog,不允許容錯的話使用set
基數=不重複元素的個數
網頁的UV(一個人訪問了一個網站多次,但是還是算作一個人
127.0.0.1:6379> pfadd key1 a b c d e f g #創建一組元素
(integer) 1
127.0.0.1:6379> pfcount key1 #統計key1中基數的數量
(integer) 7
127.0.0.1:6379> pfadd key2 f g h i z k b c
(integer) 1
127.0.0.1:6379> pfcount key1
(integer) 7
127.0.0.1:6379> pfmerge key3 key1 key2 #合併兩組key1和key2
OK
127.0.0.1:6379> pfcount key3
(integer) 11
Bitmap
Bitmap就是通過一個bit
位來表示某個元素對應的值或者狀態。Bitmaps位圖,只有0和1兩個狀態。
位存儲。可以用來統計用戶信息,登陸,未登錄;打卡。
用bitmap來記錄週一到週日的打卡:
127.0.0.1:6379> setbit sign 0 1
(integer) 0
127.0.0.1:6379> setbit sign 1 1
(integer) 0
127.0.0.1:6379> setbit sign 2 1
(integer) 0
127.0.0.1:6379> setbit sign 3 1
(integer) 0
127.0.0.1:6379> setbit sign 4 0
(integer) 0
查看某一天是否打卡:
127.0.0.1:6379> getbit sign 3
(integer) 1
查看一週打卡的天數:
127.0.0.1:6379> bitcount sign
(integer) 4