Redis學習(十六)高階資料型別

2021-10-06 03:53:27 字數 1495 閱讀 2460

bitmaps

hyperloglog

geo以位(bit)來儲存資料,用於儲存簡單的狀態資料

用法相當於乙個boolean型別的list集合 

注意:如果我們設定乙個值的下標非常大,而下標之前的所有資料將會用0來補充

//    在指定位置上獲取值

getbit key offset

// 在指定位置上設定值

setbit key offset value

// 對指定key按位進行操作,並將結果儲存到destkey中

bitop op destkey key1 [key2...]

// 統計指定key中1的數量

bitcount key [start end]

and: 交集

or:並集

not:非

xor:異或

運用了loglog演算法

用來做基數統計(資料集去重後的元素的個數)

//    新增資料

pfadd key element [element...]

// 統計資料

pfcount key [key...]

// 合併資料

pfmerge destkey sourcekey [sourcekey...]

有些小夥伴會有疑問,就是說既然我都有了set資料型別,還用hyperloglog有啥用?

hyperloglog只進行基數統計,並不儲存資料,只記錄數量不記錄資料

消耗空間很小,只占用12k記憶體來記錄基數,12k的記憶體並不是新增資料就一下占用12k,是隨著資料的不斷增大而增大

核心演算法是基數估值演算法,擁有0.81%的誤差

執行pfmerge後占用記憶體12k,無論之前的資料有多大

用於地理位置計算的相關操作

//    新增座標點

geoadd key longitude latitude member [longitude latitude member...]

// 獲取座標點

geopos key member [member ...]

// 計算座標點距離

geodist key member1 member2 [unit]

// 根據座標求範圍內的資料

georadius key longitude latitude radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count]

// 根據點求範圍內資料

georadiusbymember key member radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count]

// 獲取指定點對應座標hash值

geohash key member [member...]

Redis高階資料型別

獲取指定key對應偏移量上的bit值 getbit key offset 設定指定key對應偏移量上的bit值,value只能是1或0 setbit key offset value 對指定key按位進行交 並 非 異或 and or not xor 操作,並將結果儲存到destkey中 bitop...

Redis核心配置 Redis高階資料型別使用

daemonize yes no 伺服器是否已守護程序方式執行 bind 127.0.0.1 繫結主機 port 6379 設定埠 databases 16 設定資料庫數量 loglevel debug verbose notice warning 設定日誌級別 logfile 埠號.log 設定日...

redis 學習(一 redis資料型別)

一 reids資料型別 1.string 存 set key value 取 get key 2.hash 存 hmset key field value 取 hget key field 3.list 新增 lpush key value 遍歷 lrange key start stop redi...