Top Banner
Please visit: http://bit.do/redis We will be using this data for our presentation!
15

Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Jan 16, 2017

Download

Technology

Redis Labs
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Please visit:

http://bit.do/redis

We will be using this data for our presentation!

Page 2: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Redis 3.2 and GeospatialAndrew Bass, Deanna Shih, and Sean Yesmunt

Page 3: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

• Students at Coding House in Fremont, CA • Andrew Bass • Deanna Shih • Sean Yesmunt • Sergio Pradapaceme.us

3

Who are we?

Page 4: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

• Stable as of May 6, 2016

• Includes a new set of GEO commands for geo indexing

• Simply put, saves locations and compares them

• Geo indexed data is a special sorted set

4

Redis 3.2 and GEO

Page 5: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

GEOADD key longitude latitude member GEOHASH key member

• Longitude then Latitude

• Assumes Earth is a sphere

• Data is saved in sorted set as a Geohash

• ZREM can can be used to remove a member from the key

5

GEOADD & GEOHASH

Page 6: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Divide the world in half

Each half is 0 or 1

Save that bit, then keep dividing

Images from: mapzen.com/blog/geohashes-and-you/

Page 7: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

@RedisConf 122.393 W, 37.768 N

or

0100110110010001111011110

Or, in GEOHASH9q8yyg72zpm0

Images from: mapzen.com/blog/geohashes-and-you/

Page 8: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Why?

8

Redis can compare the locations as a sorted set!City Geohash

San Francisco 9q8yyg7zpm0

San Jose 9q9k6mjng

Los Angeles 9q5ctr186

London gcpvj0duq

Beijing wx4g0bm6c

Page 9: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

GEOPOS key member [member ...]

• Returns Longitude and Latitude for member of a key

• Since the data is converted to a string and back, it may be slightly different than the original GEOADD inputs

9

GEOPOS

Page 10: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

10

Longitude and Latitude Accuracy

https://en.wikipedia.org/wiki/Decimal_degrees

Page 11: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

GEODIST key member1 member2 [unit]

❖ Returns the distance between two members of a key

❖ Unit is defaulted to meters, but accepts:• m for meters

• km for kilometers

• mi for miles

• ft for feet

11

GEODIST

Page 12: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC]

• Returns members of a key within the radius from the coordinates • Options for including coordinates, distance, limit number of results,

and sort ascending or descending • Note, WITHHASH returns a 52bit integer, not the geohash.

12

GEORADIUS

Page 13: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC]

• Returns members of a key within the radius of the given member • Otherwise, same as GEORADIUS

13

GEORADIUSBYMEMBER

Page 14: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

Demo AppFind people close to you who are also at

14

Page 15: Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prada, Deanna Shih, Coding House

For another demo, check out paceme.us