Redis系列-05Redis高级特性

170 阅读1分钟

Redis除了5种数据结构之外,还提供了许多其它功能

  • 慢查询: 帮助找到系统中瓶颈的命令
  • Pipeline: 帮我们提高客户端的效率
  • 发布订阅
  • Bitmap: 位图,一种更节省内存的方案
  • HyperLogLog
  • GEO: 基于地理位置信息的定位功能

慢查询

声明周期

image-20200604192830219

  • 慢查询发生在第3阶段
  • 客户端超时不一定是慢查询,但慢查询是客户端超时的一个可能因素

两个配置

  • slowlog-max-len: 设置慢查询队列的长度(通常设置为1000左右)

    • 先进先出队列
    • 固定长度
    • 保存在内存中

    image-20200604193401921

  • slowlog-log-slower-than: 慢查询的阈值(通常设置为1ms)

    • 慢查询阈值(单位: 微秒)
    • Slowly-log-slower-than = 0 , 记录所有命令
    • Slowly-log-slower-than < 0 , 不记录任何命令

默认值

image-20200604213552706

配置方法

  1. 修改配置文件重启
  2. 动态配置
    1. config set slowly-max-len 1000
    2. config set slowly-log-slower-than 1000

慢查询命令

  1. slowlog get [n] :获取慢查询队列
  2. slowly len: 获取慢查询队列长度
  3. slowly reset: 清空慢查询队列

pipeline

什么是流水线

image-20200604214351303

流水线的作用

image-20200604214549147

发布订阅

image-20200605091856386

发布 publish

image-20200605092258389

订阅 subscribe

image-20200605092325048

取消订阅 unsubscribe

image-20200605092434829

其它API

image-20200605094251534

位图

API

setbit

image-20200605094904715

image-20200605100342777

getbit

image-20200605100538760

bitcount

image-20200605100618402

bitop

image-20200605100729314

bitpos

image-20200605100758030

实战

独立用户统计

image-20200605100953143

image-20200605101043542