An async redis client library with a minimal api
Project description
reddish - an async redis client with minimal api
Features
async
/await
usingtrio
's stream primitives (TCP, TCP+TLS, Unix domain sockets)- minimal api so you don't have to relearn how to write redis commands
- supports all redis commands including modules except
SUBSCRIBE
,PSUBSCRIBE
andMONITOR
[^footnote] - parses responses back into python types if you like (powered by pydantic)
- works with every redis version and supports both
RESP2
andRESP3
protocols
[^footnote]: Commands like SUBSCRIBE
or MONITOR
take over the redis connection for listeting to new events
barring regular commands from being issued over the connection.
Installation
pip install reddish
Minimal Example
import trio
from reddish import Redis, Command
redis = Redis(await trio.open_tcp_stream('localhost', 6379))
assert b'PONG' == await redis.execute(Command('PING'))
Usage
Command with a fixed number of arguments
# simple command without any arguments
Command('PING')
# commands with positional arguments
Command('ECHO {}', 'hello world')
# commands with keyword arguments
Command('SET {key} {value}', key='foo', value=42)
Command with response parsing
# return response unchanged from redis
assert b'42' == await redis.execute(Command('ECHO {}', 42))
# parse response as type
assert 42 == await redis.execute(Command('ECHO {}', 42).into(int))
# use any type that works with pydantic
from pydantic import Json
import json
data = json.dumps({'alice': 30, 'bob': 42})
response == await redis.execute(Command('ECHO {}', data).into(Json))
assert response == json.loads(data)
Command with variadic arguments
from reddish import Args
# inlining arguments
Command('DEL {keys}', keys=Args(['foo', 'bar'])) # DEL foo bar
# inlining pairwise arguments
data = {'name': 'bob', 'age': 42}
Command('XADD foo * {fields}', fields=Args.from_dict(data)) # XADD foo * name bob age 42
Pipelining commands
foo, bar = await redis.execute_many(Command('GET', 'foo'), Command('GET', 'bar'))
Transactions
from reddish import MultiExec
tx = MultiExec(
Command('ECHO {}', 'foo'),
Command('ECHO {}', 'bar')
)
foo, bar = await redis.execute(tx)
# pipelining together with transactions
[foo, bar], baz = await redis.execute_many(tx, Command('ECHO {}', 'baz'))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
reddish-0.3.0.tar.gz
(8.4 kB
view details)
Built Distribution
File details
Details for the file reddish-0.3.0.tar.gz
.
File metadata
- Download URL: reddish-0.3.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.8 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73fb5bbb1403d28f21c8b79a4a0b19224ca7aeffc17e817d3bfbae0b1902a650 |
|
MD5 | ca54ac29486a7bd6b8340cd0a869775d |
|
BLAKE2b-256 | 26b3054b52b5d2d4a76800b1c2c8e948229f30ed983485439244aa9f59dcae6b |
File details
Details for the file reddish-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: reddish-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.8 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cdab9af9089a8a8ba821d5b68c452fde9d267def4341764a3904ff5580c4f92 |
|
MD5 | c3380316848116f9e289389600e5e802 |
|
BLAKE2b-256 | 927308f2b177e468d678116293dcf79e8f65619878fe66e4ea3912b724e5e215 |