I am in the process of learning redis and am building a geo program for learning purposes. I would like to only use redis to store the data and am trying to avoid any relational databases. My question is how to best design the database for the program. This is what the how the program goes:
1) I will create millions of random robots around the world which wander so they can have different geo coordinates (some robots can be in the exact same space).
2) Each robot will randomly send a post to the server (every few hours possibly on average) which will contain: a) the location of where the robot sent this data from (in either coordinates or geohash depending on the best implementation idea) b) some small text
3) I will have a map with all the robots and would like to be able to click on a robot and get this information: a) all the posts which were posted nearby the robot I just clicked
4) Due to the fact I will be hosting this on AWS I will need to delete the posts every couple of hours to keep the memory usage low so some type of expiration is mandatory.
My main concern is performance and I am interested in how to design the redis database.
In a single day (I will work out the math for random posts to do this) about ~500,000,000 posts will be generated.
My Incomplete ideas so far:
Idea 1
1) a post would be stored as such:
`HSET [Geohash of location] [timestamp] [small text] (<-- the value will be used in a later feature to increment the number of manual modification I make to a post).
2) I then would be able to get all the posts near a robot by sending the geohash location he is in. The downfall here is I would also need to include his 8 geohash neighbors which would require 8 more queries. Which is why I am also looking into concept of spatial proximity for this feature.
HGETALL [GeoHash Location of robot]
This would then return the field ([timestamp]) and value ("0");
3) Expiration of old posts. Since I can't use the EXPIRE command to delete fields from a hashset, I would then need to scan through all the hashset fields periodicly and find old timestamps and remove them. Since Redis only allows pattern searching this could will be difficult when all the timestamps are different.
Idea 2:
Use Redis-geo (https://matt.sh/redis-geo).
1) To store the posts I would run:
geoadd globalSet [posts_long] [posts_lat] "small text";
2) To get all the post information for a robot nearby:
georadius nyc [robots_long] [robots_lat] [X] km
This would return all posts near the robot within X kms.
3) Then I am now stuck how to remove old posts
I am in the process of learning redis and am building a geo program for learning purposes. I would like to only use redis to store the data and am trying to avoid any relational databases. My question is how to best design the database for the program. This is what the how the program goes:
1) I will create millions of random robots around the world which wander so they can have different geo coordinates (some robots can be in the exact same space).
2) Each robot will randomly send a post to the server (every few hours possibly on average) which will contain: a) the location of where the robot sent this data from (in either coordinates or geohash depending on the best implementation idea) b) some small text
3) I will have a map with all the robots and would like to be able to click on a robot and get this information: a) all the posts which were posted nearby the robot I just clicked
4) Due to the fact I will be hosting this on AWS I will need to delete the posts every couple of hours to keep the memory usage low so some type of expiration is mandatory.
My main concern is performance and I am interested in how to design the redis database.
In a single day (I will work out the math for random posts to do this) about ~500,000,000 posts will be generated.
My Incomplete ideas so far:
Idea 1
1) a post would be stored as such:
`HSET [Geohash of location] [timestamp] [small text] (<-- the value will be used in a later feature to increment the number of manual modification I make to a post).
2) I then would be able to get all the posts near a robot by sending the geohash location he is in. The downfall here is I would also need to include his 8 geohash neighbors which would require 8 more queries. Which is why I am also looking into concept of spatial proximity for this feature.
HGETALL [GeoHash Location of robot]
This would then return the field ([timestamp]) and value ("0");
3) Expiration of old posts. Since I can't use the EXPIRE command to delete fields from a hashset, I would then need to scan through all the hashset fields periodicly and find old timestamps and remove them. Since Redis only allows pattern searching this could will be difficult when all the timestamps are different.
Idea 2:
Use Redis-geo (https://matt.sh/redis-geo).
1) To store the posts I would run:
geoadd globalSet [posts_long] [posts_lat] "small text";
2) To get all the post information for a robot nearby:
georadius nyc [robots_long] [robots_lat] [X] km
This would return all posts near the robot within X kms.
3) Then I am now stuck how to remove old posts