A fast redis library written in Rust
Project description
zangy
A fast redis library for python written in Rust using PyO3.
Installation
pip install --user zangy
Building from source requires nightly Rust.
How does it work?
zangy aims to be the fastest python redis library. This is done by using pyo3 to generate shared objects in binary form. It is pretty much identical to writing this in C, but less of a pain to compile and identical in speed.
Due to being completely in Rust, zangy can't do lifetime-based connection pooling and instead will create connections on startup and not lazily. All actions are distributed over the pool based on round robin. Internally, redis-rs is used for the redis operations and tokio is used to spawn tasks outside the GIL.
Because it uses tokio and rust-level tasks, zangy unleashes maximum performance when used with a lot of concurrent things to do.
Is it fast?
Yes! It beats similar Python libraries by a fair margin. Tokio, no GIL lock and the speed of Rust especially show when setting 1 million keys in parallel.
Benchmark sources can be found in the bench
directory.
Benchmarks below done with Redis 6.0.9 and Python 3.9, aioredis 1.3.1 and the latest zangy master:
Task | aioredis operations/s | aioredis total time | zangy operations/s | zangy total time |
---|---|---|---|---|
Loop 1 million times, set key to value | 7941.61 | 2m6.054s | 8485.11 | 1m57.923s |
Set 1 million keys at once and wait for finishing | - | 0m49.797s | - | 0m25.294s |
TLDR: zangy is faster in every regard but crushes in actually concurrent scenarios.
Usage
The API is subject to change.
import zangy
# Create a pool with 2 connections and 2 pubsub connections
pool = await zangy.create_pool("redis://localhost:6379", 2, 2)
# Generic redis commands (disadvised)
await pool.execute("SET", "a", "b")
# Individual commands
value = await pool.get("a")
# Wait for pubsub messages and echo back
with pool.pubsub() as pubsub:
await pubsub.subscribe("test1")
async for (channel, payload) in pubsub:
print(channel, payload)
await pool.publish("test2", payload)
Aliases for almost all operations exist on pool (.set
, .set_ex
, .zrange
, etc).
What is not supported?
- Single connections. Just use a pool with 1 member.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for zangy-0.1.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce4368bc5287f3e326a2f18114ead0eb4c8c5ef796f227f27aa4909496941f1c |
|
MD5 | 8490a1cd5ed9e138e77931e42a52792e |
|
BLAKE2b-256 | 09bab0045b14b8710d130f4d9cc8bc642c50fea0ea105286be9e5f720d966f81 |
Hashes for zangy-0.1.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe7a4a6903a77f8fe59facdeee86ed845e9d066f1bfb02d5110f11a81c86aad8 |
|
MD5 | 93c3b0d0b2e8bf2ee1a75a006ec2a9ad |
|
BLAKE2b-256 | f0ca1bcada43d5e24c69d48863f5932fbcb165049a7ee7350961f35bdb82ccfd |