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 Distribution
Built Distributions
File details
Details for the file zangy-0.1.2.tar.gz
.
File metadata
- Download URL: zangy-0.1.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b3ce0aea87379c7cdc1c6143ffb314c0267ed4f7ed6c074bef172c12278c175 |
|
MD5 | dc949fc8d51bb362eb1990b13dfd2a35 |
|
BLAKE2b-256 | dad56de83a75653f5b7e4446c538a18b8a5863f3ba8ff48f62ebff30d6852b61 |
File details
Details for the file zangy-0.1.2-cp39-none-win_amd64.whl
.
File metadata
- Download URL: zangy-0.1.2-cp39-none-win_amd64.whl
- Upload date:
- Size: 501.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb797cc83cf3f7e1a40431dff9e8775328de74bed2af846354399f2da9baa44 |
|
MD5 | cf5fb0e5a5d7a2df4d23f9e92370bf36 |
|
BLAKE2b-256 | ea8bac050b0df340737363ff1a16f1f56da823b02df4233cd8ec514ee2f33b93 |
File details
Details for the file zangy-0.1.2-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: zangy-0.1.2-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 583.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c1cbae9533ef9938f41bab58ab4e3c88b20955c127f9ead619916ec8672017 |
|
MD5 | e49760f11207f5c3c8a1be584ed4be5f |
|
BLAKE2b-256 | 3f309b4f03252f9ecc2169d02dd9b55bfc9440bc78967411f325322e098b18e5 |
File details
Details for the file zangy-0.1.2-cp38-none-win_amd64.whl
.
File metadata
- Download URL: zangy-0.1.2-cp38-none-win_amd64.whl
- Upload date:
- Size: 501.6 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 316c4056fa52cee2bd5e95f064f3f0d3e8156baa00f8abd1d24f51bffcec7d6c |
|
MD5 | c45bb04b6f07493527feec4b6bbd79ea |
|
BLAKE2b-256 | b6a206501e9690997489a1ad8377b917b6cbe8d51cb6bec863a6b4492cf74cdc |
File details
Details for the file zangy-0.1.2-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: zangy-0.1.2-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 583.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f1c7d67c2e2b92e0be798c3b845781990ef594f885545cb9b9c12b7caa5952 |
|
MD5 | 81eb8b6471c71566ad41a06f906b95dc |
|
BLAKE2b-256 | cc1d37483fd9052cca2c1ec467ba9ce2b5daec68505cafbad05f5f9f8084d8ce |