1、geospatial 地理位置

有效的经度从-180度到180度

有效的纬度从-85.05112878度到85.05112878度

当坐标位置超出上述指定范围时,该命令将会返回一个错误

底层实现原理是Zset

设置成员的经纬度:geoadd china:city 116.408 39.904 beijing

127.0.0.1:6379> geoadd china:city 116.408 39.904 beijing #精度 维度 北京
(integer) 1
127.0.0.1:6379> geoadd china:city 121.445 31.213 shanghai #精度 维度 上海
(integer) 1
127.0.0.1:6379> geoadd china:city 117.246 39.117 tianjin #精度 维度 天津
(integer) 1
127.0.0.1:6379> geoadd china:city 117.009 36.663 jinan #精度 维度 济南
(integer) 1

获取指定成员的经纬度:geopos china:city beijing

127.0.0.1:6379> geopos china:city beijing #获取北京经纬度
1) 1) "116.40800267457962036"
2) "39.90399988166036138"
127.0.0.1:6379> geopos china:city chongqing #获取重庆经纬度 不存在返回null
1) (nil)

计算两个成员之间的距离(默认为米):geodist china:city beijing shanghai

127.0.0.1:6379> geodist china:city beijing shanghai #北京上海直线距离 米
"1068232.0171"
127.0.0.1:6379> geodist china:city beijing shanghai km #北京上海直线距离 千米
"1068.2320"

获取附近的人(经纬度):georadius china:city 116.408 39.904 300 km withdist

当前精度 维度 半径距离 单位

127.0.0.1:6379> georadius china:city 116.408 39.904 300 km withdist
1) 1) "tianjin"
2) "113.2839"
2) 1) "beijing"
2) "0.0002"

获取附近的人(经纬度指定数量):georadius china:city 116.408 39.904 300 km withdist count 1

127.0.0.1:6379> georadius china:city 116.408 39.904 300 km withdist count 1
1) 1) "beijing"
2) "0.0002"

获取附近的人(成员):georadiusbymember china:city beijing 300 km withdist

当前精度 维度 半径距离 单位

127.0.0.1:6379> georadiusbymember china:city beijing 300 km withdist
1) 1) "tianjin"
2) "113.2837"
2) 1) "beijing"
2) "0.0000"

获取附近的人(成员指定数量):georadiusbymember china:city beijing 300 km withdist count 1

127.0.0.1:6379> georadiusbymember china:city beijing 300 km withdist count 1
1) 1) "beijing"
2) "0.0000"

查看所有的成员:zrange china:city 0 -1

127.0.0.1:6379> zrange china:city 0 -1
1) "shanghai"
2) "jinan"
3) "tianjin"
4) "beijing"

删除指定成员:zrem china:city jinan

127.0.0.1:6379> zrem china:city jinan #删除济南
(integer) 1
127.0.0.1:6379> zrange china:city 0 -1
1) "shanghai"
2) "tianjin"
3) "beijing"

2、hyperloglogs 基数统计

基数:不重复的元素

A{1、3、5、7、7、9}
不记录重复的元素 = 5{1、3、5、7、9}
比如:统计网站的UV(独立访客)
传统方式可以用set集合 但比较浪费空间 而且相对比较麻烦

存值:pfadd view a a b c d e f g h i j

统计数量:pfcount view

127.0.0.1:6379> pfadd view a a b c d e f g h i j #存入11个值 其中a是重复的
(integer) 1
127.0.0.1:6379> pfcount view #返回10 不统计重复的值
(integer) 10

不重复并集:pfmerge otherview view view2

127.0.0.1:6379> pfadd view a a b c d e f g h i j
(integer) 1
127.0.0.1:6379> pfcount view #view中有10个
(integer) 10
127.0.0.1:6379> pfadd view2 h i j k
(integer) 1
127.0.0.1:6379> pfcount view2 #view2中有4个 但h i j与view中是重复的
(integer) 4
127.0.0.1:6379> pfmerge otherview view view2 #把view和view2合并到otherview
OK
127.0.0.1:6379> pfcount otherview #11个 已去掉重复的
(integer) 11

3、Bitmap 位图

二进制 只有0和1两个值 比如统计活跃 不活跃用户 登录 未登录用户 打卡状态等

存值:setbit sign 20200406 1

127.0.0.1:6379> setbit sign 20200406 1 #4月6日已打卡
(integer) 0
127.0.0.1:6379> setbit sign 20200407 0 #4月7日未打卡
(integer) 0
127.0.0.1:6379> setbit sign 20200408 0 #4月8日未打卡
(integer) 0

查看某一天打卡状态:getbit sign 20200407

127.0.0.1:6379> getbit sign 20200407
(integer) 0
127.0.0.1:6379> getbit sign 20200406
(integer) 1

统计打卡天数(只能统计为1的):**bitcount ** sign

127.0.0.1:6379> bitcount sign

最新文章

  1. [转载]jQuery中wrap、wrapAll和wrapInner用法以及区别
  2. 如何查看PYTHON Django的保存路径
  3. JS --正则表达式验证、实战之邮箱模式
  4. 判断cdn上的图片可以正常访问到
  5. vertical sync
  6. CodeSmith datagridview属性
  7. 无向图求割点 UVA 315 Network
  8. 第四课 Grid Control实验 GC Agent安装(第一台机器部署) 及卸载
  9. Oracle Spatial-元数据及SDO_GEOMETRY
  10. codevs 1515 跳 贪心+lucas
  11. 在js中做数字字符串加0补位,效率分析
  12. 采用Flume实时采集和处理数据
  13. hdu3689(kmp+dp)
  14. mark笔记
  15. 转 html5离线储存,application cache,manifest使用体验
  16. 关于redis数据库的简单思考
  17. 微信小程序开发学习(一)
  18. idea创建项目报错(Maven execution terminated abnormally (exit code 1) )解决方案
  19. web全栈架构师[笔记] — 03 html5新特性
  20. Android APP常见的5类内存泄露及解决方法

热门文章

  1. 关于用命令行和idea对项目打jar包
  2. WEB缓存控制机制与varnish简介
  3. GIS中地图投影的定义
  4. mysql的Ft_hints: no_ranking
  5. 使用RandomString方法后,结果返回相同的随机数解决办法
  6. TCP漫谈之keepalive和time_wait
  7. jenkins集成sonarQube实现代码质量检查
  8. dis反汇编查看实现
  9. PTA数据结构与算法题目集(中文) 7-3
  10. 个推push数据统计(爬虫)