In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Redis how to achieve query nearby people function, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Import redis.clients.jedis.GeoCoordinate
Import redis.clients.jedis.GeoRadiusResponse
Import redis.clients.jedis.GeoUnit
Import redis.clients.jedis.Jedis
Import java.util.HashMap
Import java.util.List
Import java.util.Map
Public class GeoHashExample {
Public static void main (String [] args) {
Jedis jedis = new Jedis ("127.0.0.1", 6379)
Map map = new HashMap ()
/ / add Xiaoming's position
Map.put ("xiaoming", new GeoCoordinate (116.404269, 39.913164)
/ / add the location of Xiao Hong
Map.put ("xiaohong", new GeoCoordinate (116.36, 39.922461)
/ / add the location of Xiao Mei
Map.put ("xiaomei", new GeoCoordinate (116.499705, 39.874635)
/ / add a waiter
Map.put ("xiaoer", new GeoCoordinate (116.193275, 39.996348)
Jedis.geoadd ("person", map)
/ / query the straight line distance between Xiao Ming and Xiao Hong
System.out.println ("Xiao Ming and Xiao Hong are apart:" + jedis.geodist ("person", "xiaoming")
"xiaohong", GeoUnit.KM) + "KM")
/ / inquire about people who are 5 kilometers near Xiaoming.
List res = jedis.georadiusByMemberReadonly ("person", "xiaoming"
5, GeoUnit.KM)
For (int I = 1; I < res.size (); iTunes +) {
System.out.println ("people near Xiaoming:" + res.get (I) .getMemberByString ())
}
}
}
The results of the above procedures are as follows:
Distance between Xiao Ming and Xiao Hong: 3.9153 KM
People near Xiaoming: xiaohong
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.