Redis Cluster
Every key hashes to one of 16,384 slots: CRC16 of the key, mod 16,384. Each node holds a range of slots, and a command runs on the node that holds its key's slot.
| Node | Slots |
|---|---|
| Redis 1 | 0–2730 |
| Redis 2 | 2731–5460 |
| Redis 3 | 5461–8191 |
| Redis 4 | 8192–10922 |
| Redis 5 | 10923–13652 |
| Redis 6 | 13653–16383 |
Each run loads every driver into the key key_for(lat, lng) returns, with the driver's id as the member.
Helpers
For splitting the map into a grid of cells about 10 km across. Import them with from framework import get_cell, cells_near.
get_cell(lat, lng) | The cell a position is in, as text: "377:-1225" |
cells_near(lat, lng, radius_km) | Every cell a search can reach: the position's own, and any neighbor the radius crosses into |
Redis
await redis.geosearch(key, ...) | Members of one key near a point |
It returns each driver's id, distance and (lng, lat), nearest first:
[["8812", 0.41, (-122.4194, 37.7749)], ["301", 0.87, (-122.4268, 37.7812)], ...]Python · 32 linesStarter code · Ctrl/⌘ + Enter to run
SystemBroke
No runs yet.
Run the simulation to send this kata's traffic to your code. Hidden checks grade what it does.