Home / Companies / Redis / Blog / Post Details
Content Deep Dive

Async/Await Programming Basics with Python Examples

Blog post from Redis

Post Details
Company
Date Published
Author
Redis
Word Count
1,334
Company Posts That Month
4
Language
English
Hacker News Points
-
Post removed?
No
Summary

This post discusses the basics of async/await in Python, focusing on improving program throughput by reducing idle time when performing I/O operations. The author chooses to use Python 3 as an example since its concurrency primitives are relatively recent and may not be familiar to many users. The main reason for using async/await is to improve performance in programs that do a lot of network communication, such as those connected to a Redis database. The author provides a code sample that tracks wins for a hypothetical game, updating a Redis Sorted Set that acts as the leaderboard, and then shows an equivalent non-blocking version of the code using aio-libs/aioredis. However, the initial non-blocking version does not improve performance due to overusing the await keyword, which blocks execution flow. The author addresses this by introducing asyncio.gather, a synchronization primitive that allows scheduling multiple tasks concurrently. By applying asyncio.gather, the program can now process each batch of events concurrently, improving throughput without significant changes to the code.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.