目录
- 慢查询
- Bitmap
- pipeline
- 发布订阅
- HyperLogLog
- GE0
一、慢查询
生命周期
生命周期
两个配置
image.png
image.png
image.png
三个命令
image.png
运维经验
image.png
二、bitMap(位图: 以二进制的位
进行操作)
三、pipeline
- 什么是流水线
- 将需要操作的命令进行打包。 交由redis服务端依次执行。再由服务端将执行结果依次返回
- 一次pipeline(n条命令) = 1次网络时间 + n次命令时间
image.png
image.png
注意点
- Redis的命令时间是微妙级别
- pipeline每次条数都要控制(网络成本大)
-
客户端实现
//没有pipeline Jedis jedis = new Jedis(127.0.0.1,6379); for(int i=0; i<10000;i++){ jedis.hset("hashkey:"+i,"field"+i,"value"+i); } //使用pipeline Jedis jedis = new Jedis(127.0.0.1,6379); for(int i=0; i<100; i++){ Pipeline pipeline= jedis.pipeline(); for(int j=i*100;j<(i+1)*1--;j++){ pipeline.hset("hashkey:"+j,"field"+j,“value”+j); } pipeline.syncAndReturnAll(); }
-
与原生操作对比
- m操作是一个原子操作。是原生命令
- pipline是组合操作。redis需要进行拆分操作
-
使用建议
- 注意每次pipeline携带的数据
- pipeline每次操作只能作用在一个Redis节点上
- M操作与pipeline的区别
四、发布订阅
角色
- 发布者(publisher)
- 订阅者(subscriber)
- 通道(channel)
模型
发布订阅,一对多的形式。 同一个频道下。发布者发布的消息。会被每一个订阅这个频道的订阅者接收到。
image.png
image.png
API
- 发布命令
publish channel message
publish sohu:tv "hello word "
- 订阅
subscribe [channel] #一个或多个
- 取消订阅
unsubscribe [channel] #一个或多个
image.png
发布订阅与消息队列
image.png
五、HeperLogLog
介绍
- 基于HeperLogLog算法。 用极少的空间完成独立数量统计。
- 本质还是字符串
三个命令
-
pfadd key element [element ...] :
向hyperloglog添加元素 -
pfcount key [key ...]
计算hyperloglog的独立总数 -
pfmerge destkey sourcekey [sourcekey ...]
合并多个hyperloglog
image.png
image.png
内存消耗
image.png
使用经验
- 不准确。(错误率0.81%)
- 无法取出单条数据
六、GE0(地理信息定位)
简介
- GEO(地理信息定位) :存储经纬度,计算两地距离,范围计算等
API
-
geo key longitude latitude mermber [longitude latitude merber ...]
#增加地址位置信息 -
geopos key memer [member ...]
#获取地址位置信息 geodist key merber1 mermber1 [unit] #获取两个地理位置的距离。 unit m 米 ,km 千米, mi 英里,ft 尺
-
georadius
image.png
image.png
image.png
image.png
image.png
总结
- 版本 3.2+
- type geokey ==zset [ geo 的数据类型是zset]