We created an app to find nearby running partners, and to demonstrate Redis Data structures and functions. In this talk, we will review the data structures and walk through our NodeJS app that depends solely on Redis Geospatial Indexes. Functions demoed are GEOADD, ZREM, GEOHASH, GEOPOS, GEODIST, GEORADIUS, GEORADIUSBYMEMBER
2. Redis 3.2 and Geospatial
Andrew Bass, Deanna Shih, and Sean Yesmunt
3. • Students at Coding House in Fremont, CA
• Andrew Bass
• Deanna Shih
• Sean Yesmunt
• Sergio Prada
paceme.us
3
Who are we?
4. • 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
5. 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
6. 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/
7. @RedisConf
122.393 W, 37.768 N
or
0100110110010001111011110
Or, in GEOHASH
9q8yyg72zpm0
Images from: mapzen.com/blog/geohashes-and-you/
8. 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
9. 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
11. 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
12. 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
13. 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