Redis lists
A list keeps its items in order. Feeds usually push new items onto the front.
await redis.lpush(key, value, ...) | Adds to the front of the list, creating it if there's none. Returns its new length |
await redis.lpushx(key, value, ...) | Adds to the front only if the list exists. Returns its new length, or 0 |
await redis.rpush(key, value, ...) | Adds to the back |
await redis.lrange(key, 0, 19) | The first 20 items, as strings. [] if there's no list |
await redis.ltrim(key, 0, 19) | Keeps the first 20 items and drops the rest |
Each command costs Redis about the same no matter how many items it handles, so add many items with one rpush rather than a loop.
Postgres
Each run builds the database from schema.sql and fills it with 1,000 people (user1 to user1000), who each follow 100 others and have posted 20 times.
WHERE id = ANY(%(ids)s) | Rows whose id is in a Python list |
SELECT follower_id FROM follows WHERE followee_id = ... | Everyone who follows someone, through the follows_followee_id index |
Python · 65 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.