Junior — Middle
How were geographic data stored and what formats were used in Redis in your previous project?
sobes.tech AI
Answer from AI
Redis uses a special data type for storing geographic data — geospatial indexes implemented through commands like GEOADD, GEORADIUS, GEOPOS, and others.
Data is stored as coordinates (latitude, longitude) linked to a key and object name. The storage format is an internal compressed index based on geohashes, which allows for fast radius or distance queries.
Example of usage in C# with the StackExchange.Redis library:
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
// Adding a geo point
// GEOADD locations 13.361389 38.115556 "Palermo"
db.GeoAdd("locations", 13.361389, 38.115556, "Palermo");
// Finding objects within 100 km radius of a point
var nearby = db.GeoRadius("locations", 15, 37, 100, GeoUnit.Kilometers);
Thus, geospatial data is stored compactly and allows efficient spatial queries.