Postgres
UPDATE t SET n = n + 1 WHERE ... | Adds one to whatever n is when the row is updated |
UPDATE t SET ... WHERE ... RETURNING col | Returns the rows it changed, or [] if WHERE matched none |
async with postgres.transaction(): | Runs the queries inside it as one transaction |
SELECT ... FOR UPDATE | Locks the rows it reads until the transaction ends. Other writers and FOR UPDATEs wait |
Each run fills posts with 100 posts, id 1 to 100, none liked yet.
Redis
await redis.incr(key) | Adds one to the number at key, starting from 0, and returns the new number |
await redis.get(key) | The value at key as text, like "848", or None if there isn't one |