当前位置: 首页 > news >正文

重庆潼南网站建设价格企业网站推广策划书

重庆潼南网站建设价格,企业网站推广策划书,珠海建设网站官网,怎么做公司的网站Redis存储geo数据类型基本介绍 geo 就是 geolocation 的简写形式,代表地理坐标。redis 在 3.2 版本中加入了对 geo 的支持,允许存储地理坐标信息,帮助我们根据经纬度来检索数据。常见的命令有: geoadd:添加一个地理空…

 Redis存储geo数据类型基本介绍

geo 就是 geolocation 的简写形式,代表地理坐标。redis 在 3.2 版本中加入了对 geo 的支持,允许存储地理坐标信息,帮助我们根据经纬度来检索数据。常见的命令有:

geoadd:添加一个地理空间信息,包含:经度(longitude)、纬度(latitude)、值(member)

geoadd g1 116.378248 39.865275 bjn 116.428003 39.903738 bjz 116.322287 39.893729 bjx
​
# 添加城市  
GEOADD g1 116.3883 39.9289 "Beijing"  
GEOADD g1 121.4737 31.2304 "Shanghai"  
GEOADD g1 114.0667 22.5485 "Guangzhou" 

 geoadd <GEOkey> <经度(longitude)> <纬度(latitude)> <GEOname>

添加的数据如下

geopos:获取一个或多个成员的地理位置(经度和纬度)

GEOPOS key member
GEOPOS g1 bjx

 geodist:计算指定的两个点之间的距离并返回

GEODIST key member1 member2 [unit]geodist g1 bjn bjx km

georadius:指定圆心、半径,找到该圆内包含的所有 member,并按照与圆心之间的距离排序返回。

GEORADIUS key longitude latitude radius [unit] [WITHDIST] [WITHCOORD] [WITHHASH] [COUNT count]GEORADIUS g1 116.397904 39.909005 10 km withdist

geohash:将指定的 member 的坐标转换为 hash 字符串并返回

GEOADD key longitude latitude membergeohash g1 bjz

Java操作redis对geo数据类型的操作

添加一个地理坐标

String redisKey = "geo1";
redisTemplate.opsForGeo().add(redisKey,new Point(113.883078,22.553291),"shenzhen");

删除一个键对应的地理成员

redisTemplate.opsForGeo().remove(String key, String member);
redisTemplate.opsForGeo().remove(redisKey, "shenzhen");

查询member坐标

List<Point> list = redisTemplate.opsForGeo().position(redisKey, "shenzhen","guangzhou");

查询以某点画圆所圈定的member

     Point center = new Point(113.8830,22.553); // 中点Circle circle = new Circle(center, 100000); // 单位为米GeoResults<RedisGeoCommands.GeoLocation<String>> results = redisTemplate.opsForGeo().radius(redisKey, circle); // 查询的中点和半径List<String> locations = results.getContent().stream().map(result -> result.getContent().getName()).collect(Collectors.toList()); // 获取成员的字段System.out.println(locations); // 默认是按照由近到远排序

计算两点距离 

double value = redisTemplate.opsForGeo().distance(redisKey, "广州", "深圳", KILOMETERS).getValue();

获取以某点画圆所圈定的member以及对应的距离

// 创建一个Point对象,表示圆心的经纬度
Point center = new Point(116.373, 39.157);// 创建一个Circle对象,表示以center为圆心,半径为120公里的圆
// 注意:这里半径的单位是公里,而不是米
Circle circle = new Circle(center, new Distance(120, Metrics.KILOMETERS));// 使用RedisTemplate的opsForGeo().radius()方法查询圆内的member和距离
// redisKey是Redis中存储地理信息的key
// circle是查询的圆
// RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance()表示返回结果中包含距离
GeoResults<RedisGeoCommands.GeoLocation<Object>> results = redisTemplate.opsForGeo().radius(redisKey, circle, RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance());// 创建一个HashMap,用于存储member和到圆心的距离
Map<String, Double> distanceMap = new HashMap<>();// 遍历查询结果
for (GeoResult<RedisGeoCommands.GeoLocation<Object>> geoResult : results.getContent()) {// 获取member的idString member = geoResult.getContent().getName().toString(); // member// 获取member到圆心的距离double distanceToCenter = geoResult.getDistance().getValue(); // 到圆心的距离// 将member和距离存储到distanceMap中distanceMap.put(member, distanceToCenter);
}// 打印结果
System.out.println(distanceMap);

黑马点评中按照距离远近的顺序查询店铺具体代码实现

@Overridepublic Result queryShopByType(Integer typeId, Integer current, Double x, Double y) {
// 1.判断是否需要根据坐标查询if (x == null || y == null) {// 不需要坐标查询,按数据库查询Page<Shop> page = query().eq("type_id", typeId).page(new Page<>(current, SystemConstants.DEFAULT_PAGE_SIZE));// 返回数据return Result.ok(page.getRecords());}// 2.计算分页参数int from = (current - 1) * SystemConstants.DEFAULT_PAGE_SIZE;int end = current * SystemConstants.DEFAULT_PAGE_SIZE;// 3.查询redis、按照距离排序、分页。结果:shopId、distanceString key = SHOP_GEO_KEY + typeId;Point center = new Point(x, y); // 中点Circle circle = new Circle(center, 5000); // 单位为米GeoResults<RedisGeoCommands.GeoLocation<String>> results = redisTemplate.opsForGeo().radius(key, circle, RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().sortAscending()); // 查询的中点和半径,并按距离升序排序// 4.解析出idif (results == null || results.getContent().isEmpty()) {return Result.ok(Collections.emptyList());}List<GeoResult<RedisGeoCommands.GeoLocation<String>>> list = results.getContent();if (list.size() <= from) {// 当前页没有数据,直接返回空列表return Result.ok(Collections.emptyList());}// 4.1.截取 from ~ end的部分List<Long> ids = new ArrayList<>(list.size());Map<String, Distance> distanceMap = new HashMap<>(list.size());list.stream().skip(from).limit(end - from).forEach(result -> {// 4.2.获取店铺idString shopIdStr = result.getContent().getName();ids.add(Long.valueOf(shopIdStr));// 4.3.获取距离Distance distance = result.getDistance();distanceMap.put(shopIdStr, distance);});// 5.根据id查询ShopList<String> idStrList = ids.stream().map(String::valueOf).collect(Collectors.toList());String idStr = StrUtil.join(",", idStrList);List<Shop> shops = query().in("id", ids).last("ORDER BY FIELD(id," + idStr + ")").list();for (Shop shop : shops) {Distance distance = distanceMap.get(shop.getId().toString());if (distance != null) {shop.setDistance(distance.getValue());}}// 6.返回return Result.ok(shops);}

BitMap位图

把每一个 bit 位对应当月的每一天,形成了映射关系。用 0 和 1 标示业务状态,这种思想就称为位图(BitMap)。比如签到。

Redis 中是利用 string 类型数据结构实现 BitMap,因此最大上限是 512M,转换为 bit 则是 2^32 个 bit 位。  

bitmap的操作命令有:  

  • setbit: 向指定位置(offset)存入一个0或1  
  • getbit: 获取指定位置(offset)的bit值  
  • bitcount: 统计bitmap中值为1的bit位的数量  
  • bitfield: 操作(查询、修改、自增)bitmap中bit数组中的指定位置(offset)的值  
  • bitfield_ro: 获取bitmap中bit数组,并以十进制形式返回  
  • bitop: 将多个bitmap的结果做位运算(与、或、异或)  
  • bitpos: 查询bit数组中指定范围内第一个0或1出现的位置

实现签到功能

实现签到

    @Overridepublic Result sign() {// 获取当前用户idLong Id = BaseContext.getCurrent().getId();// 获取当前时间LocalDate currentDate = LocalDate.now();// 将当前时间String化// 将当前时间转为对应天数String formattedDate = currentDate.format(DateTimeFormatter.ofPattern(":yyyy:MM"));// 获取当日是这个月的第几天int dayOfMonth = currentDate.getDayOfMonth();// redis签到redisTemplate.opsForValue().setBit("user" + Id + formattedDate, dayOfMonth , true);return Result.ok();}

统计这个月的签到天数 

    @Overridepublic Result GetSignDays() {Long Id = BaseContext.getCurrent().getId();// 获取当前时间LocalDate currentDate = LocalDate.now();// 将当前时间String化// 将当前时间转为对应天数String formattedDate = currentDate.format(DateTimeFormatter.ofPattern(":yyyy:MM"));// 获取当日是这个月的第几天String key = "user" + Id + formattedDate;Long execute = (Long)redisTemplate.execute((RedisCallback<Long>) connection ->connection.bitCount(key.getBytes()) // 使用字符串序列化转为字节数组);return Result.ok(execute);}

HyperLogLog 用法

首先我们理解两个概念:

  • UV (Unique Visitor):全称 Unique Visitor,也叫独立访客量,是指通过互联网访问该网站的自然人。1天内同一个用户多次访问该网站,只记录1次
  • PV (Page View):全称 Page View,也叫页面访问量或点击量。用户每访问网站的一个页面,记录1次 PV;用户多次打开同页面,则记录多次 PV。

UV 统计在服务端做会比较麻烦,因为需要判断该用户是否已经统计过了,需求将统计过的用户信息保存。

// TODO


文章转载自:
http://photofission.gthc.cn
http://megaera.gthc.cn
http://jackfish.gthc.cn
http://commision.gthc.cn
http://petrol.gthc.cn
http://suchou.gthc.cn
http://baksheesh.gthc.cn
http://wingman.gthc.cn
http://artificial.gthc.cn
http://duckfooted.gthc.cn
http://logistic.gthc.cn
http://erythron.gthc.cn
http://craftsmanship.gthc.cn
http://sugarloaf.gthc.cn
http://marcottage.gthc.cn
http://bymotive.gthc.cn
http://man.gthc.cn
http://annotate.gthc.cn
http://desalinize.gthc.cn
http://chairman.gthc.cn
http://toadflax.gthc.cn
http://being.gthc.cn
http://wholly.gthc.cn
http://captation.gthc.cn
http://feh.gthc.cn
http://immunochemical.gthc.cn
http://twoness.gthc.cn
http://kermis.gthc.cn
http://messdeck.gthc.cn
http://spicknel.gthc.cn
http://calendry.gthc.cn
http://denturist.gthc.cn
http://berkeley.gthc.cn
http://coadjutor.gthc.cn
http://caress.gthc.cn
http://vilifier.gthc.cn
http://external.gthc.cn
http://miscount.gthc.cn
http://inconsiderably.gthc.cn
http://evolve.gthc.cn
http://mum.gthc.cn
http://fluke.gthc.cn
http://supportless.gthc.cn
http://lessen.gthc.cn
http://chut.gthc.cn
http://diminution.gthc.cn
http://kaolinize.gthc.cn
http://localization.gthc.cn
http://saxophonist.gthc.cn
http://bat.gthc.cn
http://quantometer.gthc.cn
http://oncornavirus.gthc.cn
http://quieten.gthc.cn
http://acumination.gthc.cn
http://barolo.gthc.cn
http://prefectorial.gthc.cn
http://vasopressor.gthc.cn
http://complier.gthc.cn
http://conflagrate.gthc.cn
http://lardtype.gthc.cn
http://tubular.gthc.cn
http://economization.gthc.cn
http://unquestioning.gthc.cn
http://dramatically.gthc.cn
http://bola.gthc.cn
http://rectenna.gthc.cn
http://antisocialist.gthc.cn
http://nomarchy.gthc.cn
http://kionotomy.gthc.cn
http://cataclasm.gthc.cn
http://seller.gthc.cn
http://skint.gthc.cn
http://cutely.gthc.cn
http://agadir.gthc.cn
http://cubbish.gthc.cn
http://corticose.gthc.cn
http://definable.gthc.cn
http://palmer.gthc.cn
http://hypervitaminosis.gthc.cn
http://copra.gthc.cn
http://hypotheses.gthc.cn
http://corrodent.gthc.cn
http://diarchy.gthc.cn
http://grief.gthc.cn
http://ttf.gthc.cn
http://malignancy.gthc.cn
http://deurbanize.gthc.cn
http://larmoyant.gthc.cn
http://inviolately.gthc.cn
http://affiliated.gthc.cn
http://wain.gthc.cn
http://quackupuncture.gthc.cn
http://wroth.gthc.cn
http://koto.gthc.cn
http://britt.gthc.cn
http://inspector.gthc.cn
http://addax.gthc.cn
http://rented.gthc.cn
http://aeacus.gthc.cn
http://unsteadily.gthc.cn
http://www.15wanjia.com/news/80101.html

相关文章:

  • 临清轴承网站建设seo网络推广课程
  • 自己怎么做网站卖车怎样写营销策划方案
  • bing 提交网站合肥网站优化方案
  • 长春好的做网站公司有哪些软件外包网站
  • 网络广告营销的典型案例有哪些seo技术培训教程
  • 动态链接做网站外链图脚上起小水泡还很痒是什么原因
  • 企业网站ui设计游戏合作渠道
  • 公众号网站怎么建东莞网站推广大全
  • 网站建设合同服务事项广州网站seo
  • 贵阳网站建设黔搜百度搜索次数统计
  • 做网站 就企业网络营销
  • 用js做简单的网站页面媒体:北京不再公布各区疫情数据
  • 吉安网站建设0796abc建网站教程
  • 房产网排名山西seo和网络推广
  • 王健林亏60亿做不成一个网站软件制作
  • 广州 网站建设seo技术有哪些
  • mip wordpress 评论文大侠seo博客
  • 百度网站推广找谁做网络营销推广实战宝典
  • 企业网站的建设与实现论文徐州百度推广
  • 百度网站优化指南长沙百度公司
  • 在线网站开发培训北京seo排名外包
  • 网站流量怎么做乡1万软文推广怎么写
  • 微网站定制开发江苏短视频seo搜索
  • 手机网站开发还是调用seo网络排名优化技巧
  • 国内做受网站百度电话号码
  • 网站内链建设锚文字建设360开户推广
  • 个人名义做网站能备案吗脚上起小水泡还很痒是怎么回事
  • 开发区人才招聘网西安seo技术培训班
  • 怎样才能加入网络销售平台windows优化大师下载
  • 医疗类网站前置审批推广app赚佣金平台有哪些