1、使用的Redis客户端为:ServiceStack.Redis

2、Redis 中的 GEO
Redis是我们最为熟悉的K-V数据库,它常被拿来作为高性能的缓存数据库来使用,大部分项目都会用到它。从3.2版本开始它开始提供了GEO能力,用来实现诸如附近位置(e.g.某小区附近的篮球场 )、计算距离等这类依赖于地理位置信息的功能。
本次实例Demo中用到的GEO命令有:

Redis命令 描述
GEOADD key longitude latitude member [longitude latitude member …] 将指定的地理空间位置(纬度、经度、名称)添加到指定的 key 中
GEODIST key member1 member2 [unit] 返回两个给定位置之间的距离
GEORADIUS key longitude latitude radius 以给定的经纬度为中心, 找出某一半径内的元素

3、实例Demo

 using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Text; namespace RedisDemo
{
class NearByDemo
{
public static void Start()
{
var redisMangement = new RedisManagerPool("127.0.0.1:6379");
var client = redisMangement.GetClient(); //---写入地理信息---
RedisGeo[] redisGeos = new RedisGeo[]
{
new RedisGeo()
{
Longitude=117.12,
Latitude=39.08,
Member="tianjin"
},
new RedisGeo()
{
Longitude=114.29,
Latitude=38.02,
Member="beijing"
}
};
//GEOADD key longitude latitude member [longitude latitude member ...]
//summary: Add one or more geospatial items in the geospatial index represented using a sorted set
client.AddGeoMembers("geo", redisGeos); //---获取两个地理位置之间的距离---
//GEODIST key member1 member2 [unit]
//summary: Returns the distance between two members of a geospatial index
double distance = client.CalculateDistanceBetweenGeoMembers("geo", "tianjin", "beijing", "km");
Console.WriteLine(distance); //---获取某城市方圆多少公里内的其他城市(狭义)---
//GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
//summary: Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point
List<RedisGeoResult> geoResults = client.FindGeoResultsInRadius("geo", 115.03, 38.44, , "km");
foreach (var item in geoResults)
{
Console.WriteLine($"{item.Member}--{item.Distance}--{item.Unit}");
}
}
}
}

最新文章

  1. Android系统拍照源码
  2. 快速提升word文档编写质量
  3. Oracle大数据常见优化查询
  4. 对SVM的个人理解
  5. 武汉科技大学ACM:1005: 华科版C语言程序设计教程(第二版)例题5.8
  6. Eclipse+Java+OpenCV246人脸识别
  7. Error:Failed to open zip file. Gradle&#39;s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
  8. ue4加载界面(loadingscreen)的实现
  9. Ubuntu14.04上安装Composer
  10. OO第二次博客作业——电梯调度
  11. FPGA-VHDL课堂学习笔记*01
  12. 完整卸载 kUbuntu-desktop from Ubuntu 14.04 LTS系统 ubuntu14.04 LTS 64Bit
  13. Swift学习笔记8--Optional Chaining
  14. &lt;转&gt;记dynamic的一个小坑 -- RuntimeBinderException:“object”未包含“xxx”的定义
  15. golang的json数据解析
  16. NO_DATA_FOUND ORACL NVL函数,当第一个为空时显示第二个参数值
  17. iptables说明(转)
  18. ActiveMQ:初见&amp;安装试运行
  19. Prism 4 文档 ---第10章 Silverlight和WPF之间共享代码
  20. 总结PHP删除字符串最后一个字符的三种方法

热门文章

  1. 谈谈 Promise 以及实现 Fetch 的思路
  2. C# 9.0 终于来了, Top-level programs 和 Partial Methods 两大新特性探究
  3. 报错 version `GLIBCXX_3.4.22&#39; not found
  4. day19__第三次作业
  5. python三大神器之fabric
  6. Write a program that prints its input one word per line.
  7. Centos 6.4 安装Mplayer 播放器
  8. String 类的其他功能
  9. Java基础Day08(多线程)
  10. elasticsearch集群配置 (Tobe Continue)