Redis擴展
慢查詢
生命週期
兩個配置
默認值
config get slowlog-max-len = 128
config get slowlog-log-slower-than = 10000 # 慢查詢閾值,單位:微秒
- showlog-log-slower-than = 0 :記錄所有命令
- showlog-log-slower-than < 0 :不記錄任何命令
命令
slowlog get [n]
:獲取慢查詢隊列slowlog len
:獲取慢查詢隊列長度slowlog reset
:清空慢查詢隊列
pipeline
發佈訂閱
發佈訂閱模型
命令
publish channel message
:發佈subscribe [channel]
:訂閱unsubscribe [channel]
:取消訂閱psubscribe [pattern]
:指定訂閱模式punsubscribe [pattern]
:退訂指定模式pubsub channels
:列出至少有一個訂閱者的頻道pubsub numsub [channel...]
:列出給定頻道的訂閱者數量pubsub numpat
:列出被訂閱模式的數量
消息隊列模型
Bitmap
命令
setbit key offset value
:給位圖指定索引設置值getbit key offset
:獲取位圖指定索引的值bitcount key [start end]
:獲取位圖指定範圍值爲1的個數bitop op destkey key [key...]
:將多個Bitmap的and(交集)、or(並集)、not(非)、xor(異或)操作並將結果保存在destkey中bitops key targetBit [start] [end]
:計算位圖指定範圍第一個偏移量對應值等於targetBit的位置
HyperLogLog
利用極小的空間完成獨立數量的統計。
命令
pfadd key element [element ...]
:向hyperloglog添加元素pfcout key [key ...]
:計算hyperloglog的獨立總數pfmerge destkey sourcekey [sourcekey ...]
:合併多個hyperloglog
GEO
GEO(地理信息定位):存儲經緯度,計算兩地距離,範圍計算
命令
geo add longitude latitude member
:增加地理位置信息
geopos key member [member ...]
:獲取地理位置信息
geodist key member1 member2 [unit]
:獲取兩個地理位置的距離,unit:m(米)、km(千米)、mi(英里)、ft(尺)