資料庫系列 Redis高階資料型別

2021-10-20 00:19:29 字數 1333 閱讀 8917

基礎操作

getbit key offset// 獲取指定key對應偏移量上的bit值

setbit key offset value//設定指定key對應偏移量上的bit值,value只能是1或0

擴充套件操作

bitop op destkey key1 [key2...

]//對指定key按位進行交、並、非、異或操作,並將結果儲存到destkey中

bitcount key [start end]

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

hyperloglog 是用來做基數(資料集去重後元素個數)統計的,運用了loglog的演算法

基本操作:

pfadd key element1, element2...

//新增

pfcount key1 key 2

//統計資料

pfmerge destkey sourcekey [sourcekey...

]//合併資料

說明:

用於進行基數統計,不是集合,不儲存資料,只記錄數量而不是具體資料

核心是基數估算演算法,最終數值存在一定誤差

誤差範圍:基數估計的結果是乙個帶有 0.81% 標準錯誤的近似值

耗空間極小,每個hyperloglog key占用了12k的記憶體用於標記基數

pfadd命令不是一次性分配12k記憶體使用,會隨著基數的增加記憶體逐漸增大

pfmerge命令合併後占用的儲存空間為12k,無論合併之前資料量多少

用來計算距離

操作

//新增座標點

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

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

[withdist]

[withhash]

[count count]

//獲取座標點

geopos key member [member ...

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

[withdist]

[withhash]

[count count]

//計算座標距離

geodist key member1 member2 [unit]

geohash key member [member ...

]

redis系列之 資料庫

當我們在redis資料庫中set乙個kv的時候,這個kv儲存在 如果我們get的時候,又從 get出來。時間複雜度,空間複雜的等等,怎麼優化等等一系列問題。redis伺服器將所有資料庫資訊都儲存在redis.h redisservice結構體中。如下 1 struct redisserver 列了幾...

資料庫系列 Redis通用指令

key是乙個字串,通過key獲取redis儲存的資料 key常用操作 del key exists key type key expire key seconds 有效期控制 pexpire key milliseconds ttl key 獲取有效期 pttl key keys pattern 查...

資料庫系列 Redis刪除策略

redis中的資料,在expire中以雜湊的方式儲存在其中。其value是資料在記憶體中的位址,filed是對應的生命週期 在記憶體占用與cpu占用之間尋找一種平衡,顧此失彼都會造成整體redis效能的下降,甚至引發伺服器宕機或記憶體洩露 惰性刪除 資料到達過期時間,不做處理。等下次訪問該資料時,如...